6. A BRIEF HISTORY OF SQL
• Developed at IBM in early 1970’s.
• Designed to manipulate and retrieve data stored in relational
databases
7. A BRIEF HISTORY OF SQL
• Developed at IBM in early 1970’s.
• Designed to manipulate and retrieve data stored in relational
databases
this is a problem
35. THE IDEAL PERSISTENCE LAYER:
1. To persist objects in their native state
2. Does not interfere w/ application development
36. THE IDEAL PERSISTENCE LAYER:
1. To persist objects in their native state
2. Does not interfere w/ application development
3. Provides features needed to build modern web
apps
42. SCHEMA-LESS
• Great for rapid, iterative, agile development
• Makes things possible that in an RDBMS are either
a. impossibly hard
b. virtually impossible
c. way harder than they should be
63. # index is only created if it does not exist
logs.create_index('status')
# can index on embedded documents
logs.create_index('user.first_name')
# create compound indexes
logs.create_index(
[['user.first_name', 1],
['user.last_name', 1]]
)
75. THE OBJECT MODEL
• Each ledger line item belongs to a ledger
• Each ledger line item has two (or more) ledger entries
• must have at least one credit and one debit
• credits and debits must balance
76. THE OBJECT MODEL
• Each ledger line item belongs to a ledger
• Each ledger line item has two (or more) ledger entries
• must have at least one credit and one debit
• credits and debits must balance
• These objects must be transactional
78. SQL-BASED OBJECT MODEL
@debit = Entry.new(:account => 'Cash',
:amount => 100.00, :type => 'credit')
@credit = Entry.new(:account => 'Notes Pay.',
:amount => 100.00, :type => 'debit')
@line_item = LineItem.new :ledger_id => 1, :entries => [@debit, @credit]
In a relational schema, we need a database
transaction to ensure multi-row atomicity
79. SQL-BASED OBJECT MODEL
@debit = Entry.new(:account => 'Cash',
:amount => 100.00, :type => 'credit')
@credit = Entry.new(:account => 'Notes Pay.',
:amount => 100.00, :type => 'debit')
@line_item = LineItem.new :ledger_id => 1, :entries => [@debit, @credit]
Because we need to create 3 new records in
the database here
91. CAPPED COLLECTIONS
• Fixed-sized, limited
operation, auto age-out collections
(kinda like memcached, except persistent)
• Fixed insertion order
• Super fast (faster than normal writes)
• Ideal for logging and caching
92. GREAT. WHAT’S THAT MEAN?
We can log additional pieces of arbitrary data
effortlessly due to Mongo’s schemaless nature.
108. BLOGGING APPLICATION
A post has an author
A post has many tags
A post has many comments
109. BLOGGING APPLICATION
A post has an author
A post has many tags
A post has many comments
Instead of joining separate tables,
we can use embedded documents.
114. MONGOMAPPER
•MongoDB “ORM” developed by John Nunemaker
•Very similar syntax to DataMapper
•Declarative rather than inheritance-based
•Very easy to drop into rails