Databases - Have it your way

Similar documents
Rails + Legacy Databases Brian Hogan - RailsConf 2009 twitter: bphogan IRC: hoganbp

Web Applications. Software Engineering 2017 Alessio Gambi - Saarland University

Essential SQLAlchemy. An Overview of SQLAlchemy. Rick Copeland Author, Essential SQLAlchemy Predictix, LLC

An Incredibly Brief Introduction to Relational Databases: Appendix B - Learning Rails

Contents in Detail. Foreword by Xavier Noria

Database Application Architectures

Patterns of Enterprise Application Architecture

Creating Models. Rob Allen, July 2014

Tuesday, January 13, Backend III: Node.js with Databases

Laravel-Metable Documentation

The power of PostgreSQL exposed with automatically generated API endpoints. Sylvain Verly Coderbunker 2016Postgres 中国用户大会 Postgres Conference China 20

STARCOUNTER. Technical Overview

FACULTY OF ENGINEERING B.E. 4/4 (CSE) II Semester (Old) Examination, June Subject : Information Retrieval Systems (Elective III) Estelar

Rails: Models. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 25

Using Scala for building DSL s

Big Data with rubygems.org Download Data. Aja Hammerly

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Relational Databases Fall 2017 Lecture 7

DRYing Out MVC (ESaaS 5.1)"

Associations: mechanics (ESaaS 5.3)"

Installing Visual Studio for Report Design

Hellerstein/Olston. Homework 6: Database Application. beartunes. 11:59:59 PM on Wednesday, December 6 th

Submitted No Schema Type For Mysql Type Datetime

Don t Repeat Yourself Repeat Others

Introduction to NoSQL Databases

JRuby and Ioke. On Google AppEngine. Ola Bini

Advanced O/R Mapping with Glorp. Alan Knight Cincom Systems of Canada

Designing the M in MVC

Frustrated by all the hype?

PHP Object-Relational Mapping Libraries in action

Patterns Of Enterprise Application Architecture

Object-Relational Mapping Tools let s talk to each other!

Today s topics. Null Values. Nulls and Views in SQL. Standard Boolean 2-valued logic 9/5/17. 2-valued logic does not work for nulls

Principles of Ruby Applica3on Design. Dean Wampler Senior Mentor and Consultant Object Mentor, Inc. Chicago, IL

HIBERNATE MOCK TEST HIBERNATE MOCK TEST IV

Validations vs. Filters

Managing Data at Scale: Microservices and Events. Randy linkedin.com/in/randyshoup

Topics. History. Architecture. MongoDB, Mongoose - RDBMS - SQL. - NoSQL

SQL. The Basics Advanced Manipulation Constraints Authorization 1. 1

Mysql Insert Manual Timestamp Into Datetime Field

Authentication in Rails

Object Persistence Design Guidelines

Enterprise Features & Requirements Analysis For EJB3 JPA & POJO Persistence. CocoBase Pure POJO

EMF Temporality. Jean-Claude Coté Éric Ladouceur

Database Architectures

JPA Best Practices. Bruce Campbell

Ch 5 : Query Processing & Optimization

Hand Coded Applications with SQLAlchemy

zf-doctrine-audit Documentation Release latest

3 Continuous Integration 3. Automated system finding bugs is better than people

Fast Track to EJB 3.0 and the JPA Using JBoss

Rails: MVC in action

CS169.1x Lecture 6: Basic Rails" Fall 2012"

Are you using Ruby on Rails?

Slicing and Dicing Data in CF and SQL: Part 2

Call: JSP Spring Hibernate Webservice Course Content:35-40hours Course Outline

Towards a Theory of Genericity Based on Government and Binding

Convention over Configuration

DATA ACCESS TECHNOLOGIES FOR JAVA GENERAL STUDY

CS 525: Advanced Database Organization 03: Disk Organization

.NET Database Technologies. Entity Framework: Queries and Transactions

CMPE 131 Software Engineering. Database Introduction

1. Write two major differences between Object-oriented programming and procedural programming?

Stop Hacking, Start Mapping: Object Relational Mapping 101

Ruby on Rails Welcome. Using the exercise files

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

Object Persistence and Object-Relational Mapping. James Brucker

CHAPTER 1: INTRODUCING C# 3

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13

Databases. Jörg Endrullis. VU University Amsterdam

TOPLink for WebLogic. Whitepaper. The Challenge: The Solution:

Advanced Database Systems

Overview of the Ruby Language. By Ron Haley

Ruby on Rails. SITC Workshop Series American University of Nigeria FALL 2017

Introduction to Data Management. Lecture #11 (Relational Languages I)

CGS 3066: Spring 2017 SQL Reference

Cross-Platform Parallels: Understanding SharePoint (Online) Through Notes-colored glasses

3 The Building Blocks: Data Types, Literals, and Variables

Relational Algebra Homework 0 Due Tonight, 5pm! R & G, Chapter 4 Room Swap for Tuesday Discussion Section Homework 1 will be posted Tomorrow

Ch. 21: Object Oriented Databases

Introduction of Laravel and creating a customized framework out of its packages

Views in SQL Server 2000

SQL STORED ROUTINES. CS121: Relational Databases Fall 2017 Lecture 9

CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013

A c t i v e w o r k s p a c e f o r e x t e r n a l d a t a a g g r e g a t i o n a n d S e a r c h. 1

Software Project Seminar VII: Tools of the Craft. 23 march 2006 Jevgeni Kabanov

SQLAlchemy Session - In Depth

Rails Guide. MVC Architecture. Migrations. Hey, thanks a lot for picking up this guide!

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

PART I SQLAlchemy Core

Ruby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework

NoSQL systems: introduction and data models. Riccardo Torlone Università Roma Tre

Chapter 6 Object Persistence, Relationships and Queries

MISP core development crash course How I learned to stop worrying and love the PHP

Introduction to Data Management. Lecture #11 (Relational Algebra)

Part XII. Mapping XML to Databases. Torsten Grust (WSI) Database-Supported XML Processors Winter 2008/09 321

CS313D: ADVANCED PROGRAMMING LANGUAGE

In-class activities: Sep 25, 2017

SAP ABAP Training Course Content :

Relational Data Mapping with GORM. Fall Forecast 2009

Transcription:

Databases - Have it your way Frederick Cheung - kgb fred@texperts.com http://www.spacevatican.org 1

kgb Operates a number of Directory Enquiry type products in several countries Runs the 542542 Ask Us Anything SMS service in the US 542542 backend is handled by several Rails apps 2

Whats the difference between 1080i and 1080p? kgb Operates a number of Directory Enquiry type products in several countries Runs the 542542 Ask Us Anything SMS service in the US 542542 backend is handled by several Rails apps 2

Whats the difference between 1080i and 1080p? kgb What is the address for the sperm bank of Pittsburgh? Operates a number of Directory Enquiry type products in several countries Runs the 542542 Ask Us Anything SMS service in the US 542542 backend is handled by several Rails apps 2

Whats the difference between 1080i and 1080p? kgb What is the address for the sperm bank of Pittsburgh? Operates a number of Directory Enquiry type products in several countries Runs the 542542 Ask Us Anything SMS service in the US Where is the Greyhound bus station in Rochester, NY? 542542 backend is handled by several Rails apps 2

Whats the difference between 1080i and 1080p? kgb What is the address for the sperm bank of Pittsburgh? Operates a number of Directory Enquiry type products in several countries Runs the 542542 Ask Us Anything SMS service in the US Where is the Greyhound bus station in Rochester, NY? 542542 backend is handled by several Rails apps Is marijuana legal in Oregon? 2

Whats the difference between 1080i and 1080p? kgb What is the address for the sperm bank of Pittsburgh? Operates a number of Directory Enquiry type products in several countries Runs the 542542 Ask Us Anything SMS service in the US Where is the Greyhound bus station in Rochester, NY? 542542 backend is handled by several Rails apps Is marijuana legal in Oregon? What is the longest life span of a dog in recorded history? 2

ORMs Hide the gunk that map objects to database storage Eliminate a lot of the repetitive code don t forget about not relational storage (eg CouchDB) 3

Active Record within Rails redirect_to @person form_for @person rake tasks for migrations automatically configured on app load 4

What ORM agnosticism isn t gsub( ActiveRecord, DataMapper ) Not trying to make all ORM libraries look the same 5

What ORM agnosticism isn t gsub( ActiveRecord, DataMapper ) Not trying to make all ORM libraries look the same 5

Then what is it? Document / codify interactions between persistence layer and rest of Rails Grease the wheels Don t make you feel like a second class citizen Should be almost invisible to end user - things should just work 6

Choose your ORM on its features without worrying about bumps in the road 7

Patterns Active Record: An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data. (Martin Fowler) Data Mapper: A layer of Mappers hat moves data between objects and a database while keeping them independent of each other and the mapper itself. (Martin Fowler) 8

Some ORMs, side by side Active Record, DataMapper, Sequel 9

Similar features across the board User.new(params[:user]) Associations, scopes, migrations etc. Watch out for subtle differences! 10

Similar features across the board User.new(params[:user]) Associations, scopes, migrations etc. Watch out for subtle differences! #Active Record person.save! #=> raises if invalid person.save #=> returns false if invalid #Sequel person.save #=> raises if invalid person.save! #=> save ignoring validations 10

Active Record You all know it Does a lot of manipulation of SQL fragments - very difficult to build an Active Record adapter for non sql datasource SQL fragments make some things easy, others awkward 11

Active Record Evolution In the beginning conditions were strings: composing sets of conditions: yuck! hash conditions for equality & ranges named_scope and... 12

Arel - Relation Algebra generates db queries Destined to underpin future version Active Record Operations all closed under composition posts = Table(:posts) posts.where(posts[:subject].eq('bacon')) posts.join(comments).on(posts[:id].eq(comments[:post_id])) 13

DataMapper Query objects: lazy loaded definition of a query Easy to compose queries Easy construction of complicated joins Modular design all_posts = Post.all about_test = all_posts.all :subject.like => '%test%' with_comment_by_fred = about_test.all Post.comments.name => 'fred' 14

A DM using Model mappy feel to it explicit about attributes (versus checking schema) class Post include DataMapper::Resource include DataMapper::Timestamps property :id, Serial property :subject, String, :nullable => false property :body, Text, :nullable => false property :created_at, DateTime, :nullable => false property :updated_at, DateTime, :nullable => false has n, :comments end 15

Laziness attributes can be lazy loaded loads lazy loaded attributes in one query for all results in collection property groups when defining laziness same strategy for loading associations Post.get 1 => #<Post @id=1 @subject="hello world" @body=<not loaded> > 16

Laziness attributes can be lazy loaded loads lazy loaded attributes in one query for all results in collection property groups when defining laziness same strategy for loading associations Post.get 1 => #<Post @id=1 @subject="hello world" @body=<not loaded> > 16

Sequel Database toolkit - A ruby DSL for databases DB[:posts].filter { created_at > Date::today - 1}.all ORM layer (Migrations, associations etc. - the usual) Master/Slave databases, sharding pure ruby DSL for conditions Mosts things are Datasets 17

Sequel Model class Post < Sequel::Model plugin :timestamps one_to_many :comments end comments_dataset loads of customisation for eager loads inverse associations flexible - join on non standard columns 18

Very modular 19

Very modular Some high level 19

Very modular Some high level Identity map Lazy attributes Callbacks Single/Class Table inheritance 19

Very modular Some high level Identity map Lazy attributes Callbacks Single/Class Table inheritance Some quite grungy 19

Very modular Some high level Identity map Lazy attributes Callbacks Single/Class Table inheritance Some quite grungy Boolean readers Association proxies 19

Monolithic vs Modular Active Record in theory modular, but no easy way to choose DM explicitly modular: plugins implement validations, migrations,... Sequel::Model entirely plugin driven Modularity great when you know what you re doing, but... Tyranny of choice? 20

Conditions #Active Record Post.all :conditions => ["subject like?", "%bacon%"] Post.all :conditions => {:approved => true} Post.all :conditions => ["comments.name like?", "%bacon%"], :joins => :comments, :select => "distinct posts.*" #DataMapper Post.all :subject.like => '%bacon%' Post.all Post.comments.name.like => '%fred%' #Sequel Post.filter {subject.like '%test%'}.all Post.select('distinct posts.*').inner_join(:comments, :post_id => :id).filter {comments name.like '%test%'}.all 21

More Finders #Active Record Post.find :all, :include => :comments, :order => 'created_at desc' #DataMapper Post.all :order => [:created_at.desc] #Sequel Post.eager(:comments).order(:created_at.desc).all Post.eager_graph(:comments).order('posts.created_at desc').all 22

You can use these today You can already build apps with other data stores You can use some of the niceties like redirect_to @person You need to figure out dependencies between Action Pack and Active Record Compatibility worries 23

Little niggles Action summary doesn t count time in DM/ Sequel as database time Some manual setup have to define to_param 24

Code time! 25

That s all folks! fred@texperts.com http://www.spacevatican.org 26