Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Making Relational Cool Again (or: JavaScript on...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Tim Griesser
May 27, 2015
Technology
460
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Making Relational Cool Again (or: JavaScript on ACID)
JSConf 2015
Tim Griesser
May 27, 2015
Transcript
116 slides
Making Relational Cool Again @tgriesser
Making Relational Cool Again @tgriesser or: JavaScript on ACID
sequel
SQL
None
None
None
None
None
None
Functional, (prototypal) OO Loose, duck Static, strong Declarative, Procedural
Operators? + -
Operators? 0.1 + 0.2 // 0.30000000000000004
None
–Me “Languages that will probably never die.”
None
None
None
None
42-
None
None
None
None
None
None
–Matthew Daly, Stack Overflow User “A degree of antipathy toward
relational databases”
“Poorly supported compared to non- relational databases” –Matthew Daly, Stack
Overflow User
node- node- node- node- mysql postgres mariasql sqlite3
Existing SQL Libs? Common DBAPI? Higher level abstractions
Existing SQL Libs? Database specific Mix of ORM layer and
query layer No transaction api!! "Jack of All Trades" DIY: gets you most of the way there, but…
None
None
Query builder Eloquent Promises Models, Collections, Events
None
None
None
None
None
None
None
None
None
None
Connection Pooling Grammar Schema (DDL) Builder Migrations Seeding Expression Builder
DB Client Transactions
Simple Configuration
Simple Configuration WebSQL
Simple Configuration WebSQL
SQL, as you would write it
Joins
Joins with multiple clauses
Subqueries
Subqueries
Other Builder Features • Raw queries • Aggregate queries (min,
max, sum) • Column, subquery aliasing ".as()" • Normalizes missing data in inserts • Tries hard to not let you screw up
…or: JavaScript on ACID
None
Atomicity Consistency Isolation Durability
Transactions Snapshot state of the world Ability to ROLLBACK Prevent
others from altering data as you’re working with it (Locks) A little trickier to pull off in Node
1. Register a user, giving them an ID 2. Send
that to a third party service, registering the user 3. Create additional account rows 4. Return response to the user
None
1. Register a user, giving them an ID 2. Send
that to a third party service, registering the user catch, rollback 1 3. Create additional account rows catch, rollback 1, 3? 4. Return response to the user
None
None
None
None
None
Nesting Transactions SAVEPOINT ROLLBACK TO _____
"Batteries Included" • Pooling • Schema Building • Migrations •
Seeding • Callbacks (.asCallback) • Streams (.pipe, .stream) • Events • .toString()
None
Object Relational Mapper
Object Relational Mapper • Takes care of standard SQL queries
for you, especially for common CRUD operations • model.fetch() • model.fetchAll() • model.save() • model.destroy()
• One-To-One • hasOne • belongsTo • One-To-Many • hasMany
• Many-To-Many • belongsToMany Association Types
• One-To-One • hasOne • belongsTo • One-To-Many • hasMany
• Many-To-Many • belongsToMany Association Types
• One-To-One • hasOne • belongsTo • One-To-Many • hasMany
• Many-To-Many • belongsToMany Association Types
• Mapping a single model to multiple model types •
Picture for employees, for products Polymorphic Associations
Builds on Knex
None
None
Eager Loading • Avoids the N+1 Query Problem • Find
an account with associated posts, the comments on those posts, and the accounts that made the comments.
None
Eager Loading • Avoids the N+1 Query Problem • Find
an account with "approved" associated posts, the comments on those posts, and the accounts that made the comments.
Dynamically constrain relations
Eager Loading
"Tapping into" the query chain Allows for adding additional query
parameters dynamically to the model's query
Transactions In Bookshelf, each async call (fetch, save, create, load,
destroy), takes an “options” object which may optionally take a {transacting: t} - where “t” is the object in the transaction closure
None
None
None
Shared models: Sounds great, not as great in practice
None
None
…not the first to do this
…not the last to do this
None
None
None
None
None
None
None
None
None
None
Just some of what's out there…
…this still isn't enough
Don't Reinvent the wheel
Don't Reinvent the wheel
! Reinvent the wheel
! Reinvent the wheel*
! Reinvent the wheel* * just not on the client
side…
! Reinvent the wheel* * just not on the client
side…
! Reinvent the wheel
Take a look at other libraries
Take a look at other languages
Node: a target for traditional "CRUD" web applications
Thanks! @tgriesser
More Decks by Tim Griesser
See All by Tim Griesser
SDL as an Artifact: Code-First Schemas in TS & JS
tgriesser
0
180
SDL as an Artifact: Code-First Schemas and GraphQL Nexus
tgriesser
0
230
End-to-End Testing for the Modern Web
tgriesser
0
190
Paving a New Path for GraphQL Schemas
tgriesser
0
120
Embracing the Power of GraphQL
tgriesser
2
1.1k
Redux: A Predictable State Container for JavaScript Apps
tgriesser
2
470
The Future is Now: JavaScript, ES6, and Babel JS
tgriesser
7
1.3k
Data Based JavaScript
tgriesser
1
290
Nodevember - Making Relational Cool Again
tgriesser
1
220
Other Decks in Technology
See All in Technology
SSFの現在地 ― CAEP/RISCからAI Identityへ
oidfj
0
460
マネージャーをエスパーにしない マネジメントされる側から始める、働きやすい現場づくり
comi190327
1
730
人間+AIを「チーム」としてプロセスを再設計する
littlehands
4
3.4k
プロダクションコードにおける encoding/json から encoding/json/v2 へのスムーズな移行
sansantech
PRO
1
440
属人化したISMS運用をGitHubとAIで仕組み化した1年間の記録
sioncojp
4
2.7k
Kansai WordPress Meetup@大阪『ブロックテーマを作る上で知っておくべきこと
torounit
0
220
3文字略語に騙されない! 世界一わかりやすい『EDR』超入門
kamadamakoto
1
240
速くなるほど、深く考える AI時代のQAに学ぶ
kobayashiyorimitsu
0
260
目を覚ませ!僕らの認証情報が何者かに侵略されてるぞ
tkito
2
440
狙われているAPIの脆弱性!今こそ手をつけるべき根本的な対策とは?
nagix
0
150
パスワードのない鍵で、 データを手元に置く
ginjihayashi
0
260
「任されビリティ」で引き受けて「よしなりてぃ」に頼らず任せる / Accept tasks with "makasarebility" and hand them over without relying on "yoshinarily"
pauli
1
750
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Prompt Engineering for Job Search
mfonobong
0
590
Side Projects
sachag
456
43k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
Paper Plane (Part 1)
katiecoart
PRO
3
12k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
670
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
1
240
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
4
1.3k
Tell your own story through comics
letsgokoyo
1
1.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
The SEO Collaboration Effect
kristinabergwall1
1
620