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
Intro to Brookshelf ORM
Search
aaronmoodie
October 15, 2015
Technology
280
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Intro to Brookshelf ORM
A simple intro the the Bookshelf ORM that I gave at Brooklyn JS #24
aaronmoodie
October 15, 2015
More Decks by aaronmoodie
See All by aaronmoodie
Etsy Patterns
aaronmoodie
1
240
CreativeMornings Melbourne
aaronmoodie
2
170
Other Decks in Technology
See All in Technology
AI Native Platform Engineering 〜PlatformとAgileで“作る速さ”を“価値”へ〜
uya116
0
300
C#未経験の僕がAIに読めるコードを書かせるまで
maguroalternative
0
330
覗いてみよう 関数型ビジュアル言語×2Dグラフィックスの世界
yohyamasaki
0
140
spanner-autoscalerに学ぶ CRD設計パターン 〜自動化と緊急時対応を両立する Kubernetesコントローラーの作り方〜
tkuchiki
0
190
Azure Serverless 2026:Production-ready な AI エージェント基盤 / Azure Serverless 2026: Production-Ready AI Agent Platform
miyake
2
640
あけおめLINE 傾向とその対策
nasa9084
0
340
Apache Iceberg が拓く AI 時代のオープンレイクハウス
tomtanaka
0
120
AIは推し活である。
kurazuuuuuu
2
990
行動するAIのためのオントロジー | DevRev — Encraft #26.pdf
dvrv_tknrszk
1
510
エージェントはローカル、検証はMicroVM — Lambda MicroVMsでつくるServerless CI
fujioka6789
3
840
AIエージェントを安全で速い現場監督にする:Jev・Obsidian・メタハーネス
x5gtrn
PRO
0
130
音声コミュニティを守るAI監視基盤_ 90%以上の入力削減を支えたServerless設計と運用判断
shuheioka123
0
110
Featured
See All Featured
Building AI with AI
inesmontani
PRO
1
1.3k
Producing Creativity
orderedlist
PRO
348
41k
Designing for humans not robots
tammielis
254
26k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
310
Making the Leap to Tech Lead
cromwellryan
135
10k
Code Reviewing Like a Champion
maltzj
528
40k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
420
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
250
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
750
Abbi's Birthday
coloredviolet
4
10k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Visualization
eitanlees
153
17k
Transcript
Hello! I’m Aaron Moodie, a product designer at Etsy. I
like JavaScript.
A quick overview of Bookshelf.js, an ORM for Node.
slime.io
Bookshelf? Node ORM2 Sequelize? Node ORM?
- Backbone patterns - Knex queries and migrations - Some
Docs (at the time) Bookshelf.js ✔
Model & Collections
var Track = bookshelf.Model.extend({ tableName: 'tracks', hasTimestamps: true, user: function()
{ return this.belongsTo('User'); } }); var Tracks = bookshelf.Collection.extend({ model: Track }); Models and Collections define relationship
Saving and Updating
Saving and Updating // Create a new track new Track({'title':'Never
Gonna Give You Up'}) .save() .then(function(track) { console.log(track.get('title')); }); // Update existing track new Track({'title':'Never Gonna Give You Up'}) .save({'artist':'Rick Astley'}, {patch: true}) .then(function(track) { console.log(track.get('title')); });
Queries
Querying new Track({'title':'Never Gonna Give You Up'}) .fetch() .then(function(track) {
console.log(track.get('title')); }) .catch(function(err) { console.log(err); }); Model Fetch on attribute catch promise errors
Querying new Tracks() .query(function(qb) { qb.orderBy('created_at','DESC'); }) .fetch({withRelated: ['user']}) .then(function(tracks)
{ res.status(200).json(tracks); }); Collection Knex query builder related models as an array
Querying Model with fetchAll() new Track() .query(function(qb) { qb.orderBy('created_at','DESC'); })
.fetchAll({ withRelated: [ {'user': function(qb) { qb.column('id', 'username'); }}, 'votes', 'tags' ] }) .then(function(tracks) {}); ‘user’ mapped to query callback
Model (extending) var Track = bookshelf.Model.extend({ // Model attributes },
{ getRecent: Promise.method(function() { return new Track() .query({ /* build query */ }) .fetchAll({ /* fetch params */ }) .then(function(tracks) { return tracks; }) }); } });
router.get('/tracks', function(req, res, next) { Track.getRecent() .then(function(tracks) { res.status(200).send(JSON.stringify(tracks)); })
.catch(function(err) { return next(err); }); }); Much cleaner
- Knex migrations - Awesome Docs - Active updates More
Bookshelf Goodness
Thanks! @aaronmoodie