SlideShare una empresa de Scribd logo
1 de 25
BOOKSHELF.JS
http://bookshelfjs.org
sh-3.2# whoami
greg mcdowell
2
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
Models
Views
Controllers
5
Dependencies
6
lodash
1. What it is?
2. What it provides?
3. How to use it?
4. How we use it?
7
DB Abstraction
● MySQL
● Postgres
● SQLite3
● MSSQL
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 Lodash
● 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
once()
// promised triggers
triggerThen()
// event method
trigger()
Promises
or
Callbacks
or
Streams
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
less of an issue with es6
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
// orm.js – establish connection
import Knex from 'knex’;
import Bookshelf from ‘bookshelf’;
const DB = new Knex(); // knexfile.js
const Orm = new Bookshelf(DB);
export default Orm;
Access
21
// user.js – define a model for table
import Orm from ‘./orm’;
let User = Orm.Model.extend({
tableName:'users’}
);
export default User;
// users.js – user controller
import User from ‘./user’;
export default {
list(req, res) {
User.fetchAll()
.then(records => {
res.status(200).json(records);
})
.catch(err => {
res.status(400).json({error:err});
})
},
find(req, res){
User.forge(req.params.id)
.fetch()
.then(record => {
res.status(200).json(record);
})
.catch(err => {
res.status(400).json({error:err});
});
}
};
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:
Demo repo:
https://github.com/gmcdowell/bookshelf-demo
Questions ?

Más contenido relacionado

Similar a Bookshelf JS Buenos Aires NodeJS Meetup jul 2016

Open source data_warehousing_overview
Open source data_warehousing_overviewOpen source data_warehousing_overview
Open source data_warehousing_overview
Alex Meadows
 

Similar a Bookshelf JS Buenos Aires NodeJS Meetup jul 2016 (20)

Require.JS
Require.JSRequire.JS
Require.JS
 
Analysis on NoSQL: MongoDB Tool
Analysis on NoSQL: MongoDB ToolAnalysis on NoSQL: MongoDB Tool
Analysis on NoSQL: MongoDB Tool
 
Information Retrieval - Data Science Bootcamp
Information Retrieval - Data Science BootcampInformation Retrieval - Data Science Bootcamp
Information Retrieval - Data Science Bootcamp
 
Oracle Complete Interview Questions
Oracle Complete Interview QuestionsOracle Complete Interview Questions
Oracle Complete Interview Questions
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
NiFi - First approach
NiFi - First approachNiFi - First approach
NiFi - First approach
 
Rails meets no sql
Rails meets no sqlRails meets no sql
Rails meets no sql
 
NoSql Databases
NoSql DatabasesNoSql Databases
NoSql Databases
 
OpenCms Days 2012 - OpenCms 8.5: Using Apache Solr to retrieve content
OpenCms Days 2012 - OpenCms 8.5: Using Apache Solr to retrieve contentOpenCms Days 2012 - OpenCms 8.5: Using Apache Solr to retrieve content
OpenCms Days 2012 - OpenCms 8.5: Using Apache Solr to retrieve content
 
Mongodb vs mysql
Mongodb vs mysqlMongodb vs mysql
Mongodb vs mysql
 
Do’s and don’ts of a hybrid environment
Do’s and don’ts of a hybrid environmentDo’s and don’ts of a hybrid environment
Do’s and don’ts of a hybrid environment
 
ElasticSearch: Distributed Multitenant NoSQL Datastore and Search Engine
ElasticSearch: Distributed Multitenant NoSQL Datastore and Search EngineElasticSearch: Distributed Multitenant NoSQL Datastore and Search Engine
ElasticSearch: Distributed Multitenant NoSQL Datastore and Search Engine
 
Open source data_warehousing_overview
Open source data_warehousing_overviewOpen source data_warehousing_overview
Open source data_warehousing_overview
 
Look Ma! No more blobs
Look Ma! No more blobsLook Ma! No more blobs
Look Ma! No more blobs
 
No sq lv1_0
No sq lv1_0No sq lv1_0
No sq lv1_0
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
 
MIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptxMIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptx
 
A Practical Multi-Tenant Cluster
A Practical Multi-Tenant ClusterA Practical Multi-Tenant Cluster
A Practical Multi-Tenant Cluster
 
Hibernate.pdf
Hibernate.pdfHibernate.pdf
Hibernate.pdf
 
Hibernate
HibernateHibernate
Hibernate
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Bookshelf JS Buenos Aires NodeJS Meetup jul 2016

Notas del editor

  1. It’s lean Simple to read and understand and extend Flexible - validation First class transaction support
  2. Not just Models represents additional tools available
  3. 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
  4. Common Rel DB platforms
  5. If familiar with Backbone - easy
  6. Used internally on Fetch/Load, etc similar to Backbone
  7. Registry helpful if using AMD style of Dependancy loading
  8. Typical Con object, passed to Bookshelf and Bingo
  9. Red lines = Polymorphic relationships Show Demo
  10. 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.