Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Making Relational Cool Again (or: JavaScript on...
Search
Tim Griesser
May 27, 2015
Technology
440
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
More Decks by Tim Griesser
See All by Tim Griesser
SDL as an Artifact: Code-First Schemas in TS & JS
tgriesser
0
160
SDL as an Artifact: Code-First Schemas and GraphQL Nexus
tgriesser
0
220
End-to-End Testing for the Modern Web
tgriesser
0
170
Paving a New Path for GraphQL Schemas
tgriesser
0
110
Embracing the Power of GraphQL
tgriesser
2
1k
Redux: A Predictable State Container for JavaScript Apps
tgriesser
2
450
The Future is Now: JavaScript, ES6, and Babel JS
tgriesser
7
1.3k
Data Based JavaScript
tgriesser
1
270
Nodevember - Making Relational Cool Again
tgriesser
1
200
Other Decks in Technology
See All in Technology
Why is RC4 still being used?
tamaiyutaro
0
250
技術・能力を向上する原理原則 #きのこセッションa #きのこ2026
bash0c7
0
190
toB プロダクトから見たWAF
tokai235
0
260
Multi-Agent並列開発を 安全に回すための技術 / Technology for Safely Multi-Agent Parallel Development
tooppoo
0
230
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
200
どうして今サーバーサイドKotlinを選択したのか
nealle
0
150
プライバシー保護の理論と実践
lycorptech_jp
PRO
1
130
自分が詳しくない領域でAIを使う #プロヒス2026
konifar
20
8.1k
#エンジニアBooks 30分でわかる 「技術記事を書く技術」 / engineer-books 2026-06-30
jnchito
1
150
初めてのDatabricks勉強会
taka_aki
2
210
AI時代における最適なQA組織の作り方
ymty
3
260
秘密度ラベル初心者が第1歩でつまづかないための「設計・運用」ポイント
seafay
PRO
1
530
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
400
Balancing Empowerment & Direction
lara
6
1.2k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
400
Un-Boring Meetings
codingconduct
0
330
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
170
Are puppies a ranking factor?
jonoalderson
1
3.7k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Into the Great Unknown - MozCon
thekraken
41
2.6k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
150
Transcript
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