SlideShare a Scribd company logo
a JS ORM for Node.js
http://bookshelfjs.org
sh-3.2# whoami
greg mcdowell
founder & (reluctant) lead developer
@ oxigeno.co.nz & logmate.co.nz
2
Agenda
1. What it is?
2. What it provides?
3. How to use it?
4. How we use it?
3
“... library for common tasks
relating to querying, and
managing relations in, a
Relational Database.”
source: http://bookshelfjs.org
4
M+VC
5
Dependencies
6
Agenda
1. What it is?
2. What it provides?
3. How to use it?
4. How we use it?
7
DB Abstraction
● MySQL
● Postgres
● SQLite
8
Models &
Collections
● Individual database record.
● Domain-specific methods &
relations.
● Instance & Class properties.
9
** (mostly) follows
Backbone conventions
Models &
Collections
● Ordered sets of Models.
● Proxies Backbone &
Underscore.
● Instance & Class
properties.
10
** (mostly) follows
Backbone conventions
Entity
Relationships
// containment
hasOne()
hasMany()
// membership
belongsTo()
belongsToMany()
11
Entity
Relationships
// joins (bridge relations)
through(joinModel)
// joinModel methods
attach()
detach()
withPivot()
updatePivot()
12
Polymorphism
13
“.. polymorphism refers to
a languages ability to
process objects
differently depending on
their data type or class.”
source: http://webopedia.com/TERM/P/polymorphism.html
Polymorphic
Relationships
// containment
morphOne()
morphMany()
// membership
morphTo()
14
Eager &
Lazy
// eager load on instantiation of object
new M.fetch({withRelated: ‘related’})
// lazy load related data on existing object
obj.load(‘related’)
15
Events
// event handlers
on()
off()
16
// register listeners
listenTo()
stopListening()
listenToOnce()
// promised triggers
triggerThen()
** mixes in
Backbone.Events
// event method
trigger()
once()
Promises
or
Callbacks
Just use Promises cause
they’re AWESOME!
17
Utilities
Knex
- Query Builder
- Schema Builder
- Migrations & Seeds
Transactions
- alias Knex.Transaction
18
Plugins
** included
Registry
- reduce circular references
Virtuals
- calculated attributes
Visibility
- whitelist/blacklist attributes
19
Agenda
1. What it is?
2. What it provides?
3. How to use it?
4. How we use it?
20
var knex = require('knex')({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test',
charset : 'utf8'
}
});
var bookshelf = require('bookshelf')(knex);
var User = bookshelf.Model.extend({
tableName: 'users'
});
Connect
Access
21
22
Demo
Agenda
1. What it is?
2. What it provides?
3. How to use it?
4. How we use it?
23
24
25
Sample App:
https://github.com/gmcdowell/bookshelf-demo
Questions ?

More Related Content

PPTX
Bookshelf JS Buenos Aires NodeJS Meetup jul 2016
PDF
Java Internship in Noida For B.Tech, MCA
PDF
Introduction to Elasticsearch
PDF
Knex Postgresql Migration
PPT
MongoDB Pros and Cons
PPT
Ruby On Rails
PDF
Nine Neins - where Java EE will never take you
PPTX
MVC + ORM (with project implementation)
Bookshelf JS Buenos Aires NodeJS Meetup jul 2016
Java Internship in Noida For B.Tech, MCA
Introduction to Elasticsearch
Knex Postgresql Migration
MongoDB Pros and Cons
Ruby On Rails
Nine Neins - where Java EE will never take you
MVC + ORM (with project implementation)

Similar to BookshelfJS Akd Meetup Apr 2015 (20)

PPTX
Hibernate tutorial
PDF
Look Ma! No more blobs
PPT
NoSql Databases
PDF
node.js 실무 - node js in practice by Jesang Yoon
PDF
Introduction to CQ5
PDF
01 nosql and multi model database
PPT
Spring data presentation
PPT
Struts2-Spring=Hibernate
KEY
Data Abstraction for Large Web Applications
PDF
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
PDF
Expert selenium with core java
PDF
Information Retrieval - Data Science Bootcamp
PDF
Jab12 - Joomla! architecture revealed
PPTX
SQLite and object-relational mapping in Java
PDF
Require.JS
PPTX
JS - The Unknown Basics.pptx
PDF
276626961 java-j2 ee-course-curriculum-modular
PPTX
ODP
Presentation v1 (1)
ODP
Introduction to Mesos
Hibernate tutorial
Look Ma! No more blobs
NoSql Databases
node.js 실무 - node js in practice by Jesang Yoon
Introduction to CQ5
01 nosql and multi model database
Spring data presentation
Struts2-Spring=Hibernate
Data Abstraction for Large Web Applications
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Expert selenium with core java
Information Retrieval - Data Science Bootcamp
Jab12 - Joomla! architecture revealed
SQLite and object-relational mapping in Java
Require.JS
JS - The Unknown Basics.pptx
276626961 java-j2 ee-course-curriculum-modular
Presentation v1 (1)
Introduction to Mesos
Ad

BookshelfJS Akd Meetup Apr 2015

Editor's Notes

  • #5: It’s lean Simple to read and understand and extend Flexible - validation First class transaction support
  • #6: Not just Models represents additional tools available
  • #7: Backbone - gives structure to Web Apps -> provides key-value binding, events and RESTful Api connection Underscore - JS Lib of useful functions/helpers = tool kit analogy Promises - represents state of async operation - intuitive chaining. Knex - batteries included SQL query builder
  • #9: Common Rel DB platforms
  • #10: If familiar with Backbone - easy
  • #17: Used internally on Fetch/Load, etc similar to Backbone
  • #20: Registry helpful if using AMD style of Dependancy loading
  • #22: Typical Con object, passed to Bookshelf and Bingo
  • #23: Red lines = Polymorphic relationships Show Demo
  • #25: Replaced RoR API for Mobile App Rails Web for Admins Required 2 skill sets in Biz: App build on MarionetteJS Implemented API for Mobile App & Admins (decoupled) Est. API for Integration partners Opens possibility for Electron Apps in future & others.