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
1
400
Making Relational Cool Again (or: JavaScript on ACID)
JSConf 2015
Tim Griesser
May 27, 2015
Tweet
Share
More Decks by Tim Griesser
See All by Tim Griesser
SDL as an Artifact: Code-First Schemas in TS & JS
tgriesser
0
120
SDL as an Artifact: Code-First Schemas and GraphQL Nexus
tgriesser
0
160
End-to-End Testing for the Modern Web
tgriesser
0
140
Paving a New Path for GraphQL Schemas
tgriesser
1
84
Embracing the Power of GraphQL
tgriesser
2
800
Redux: A Predictable State Container for JavaScript Apps
tgriesser
2
410
The Future is Now: JavaScript, ES6, and Babel JS
tgriesser
7
1.2k
Data Based JavaScript
tgriesser
1
240
Nodevember - Making Relational Cool Again
tgriesser
1
190
Other Decks in Technology
See All in Technology
Docker Desktop で Docker を始めよう
zembutsu
PRO
0
160
深層学習と3Dキャプチャ・3Dモデル生成(土木学会応用力学委員会 応用数理・AIセミナー)
pfn
PRO
0
460
dbtを中心にして組織のアジリティとガバナンスのトレードオンを考えてみた
gappy50
0
240
re:Invent 2024のふりかえり
beli68
0
110
PaaSの歴史と、 アプリケーションプラットフォームのこれから
jacopen
7
1.4k
RubyでKubernetesプログラミング
sat
PRO
4
160
あなたの知らないクラフトビールの世界
miura55
0
120
カップ麺の待ち時間(3分)でわかるPartyRockアップデート
ryutakondo
0
140
AWSマルチアカウント統制環境のすゝめ / 20250115 Mitsutoshi Matsuo
shift_evolve
0
110
2024AWSで個人的にアツかったアップデート
nagisa53
1
110
駆け出しリーダーとしての第一歩〜開発チームとの新しい関わり方〜 / Beginning Journey as Team Leader
kaonavi
0
120
東京Ruby会議12 Ruby と Rust と私 / Tokyo RubyKaigi 12 Ruby, Rust and me
eagletmt
3
870
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
173
51k
A Modern Web Designer's Workflow
chriscoyier
693
190k
The Power of CSS Pseudo Elements
geoffreycrofte
74
5.4k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
192
16k
Docker and Python
trallard
43
3.2k
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