SlideShare a Scribd company logo
1 of 31
Working with LoopBack Models
Raymond Feng
Co-Founder and Architect
About StrongLoop
• Founded 2012
• Develop and support…
– LoopBack: Open Source Mobile Backend-as-a-Service
– StrongOps (formally NodeFly): Real-time performance monitoring
– StrongNode: Support for StrongLoop and public Node.js modules

• Also maintains and/or contributes to the npm ecosystem:
– node-inspector, node-reggie plus over 30 more modules

2
The Problem: Apps Need Data

•
•
•
•
•

Not authorized (AAA)
XML (Transform)
Too much data (Filter)
Combine multiple DBs (Join)
50k phones kill DB (Cache)
Introducing LoopBack
• How can we build scalable Enterprise mobile apps?
• Mobile Backend-as-a-Service (e.g. a private Parse you control)
• Connects devices and browsers to Enterprise data
• Written in Node.js – proven language for mobile backends
• Open source – extensible by design
• On-premise or on your favorite cloud
• Android and iOS SDKs

4
LoopBack Architecture

5
How it Works

6
LoopBack
• Backend for mobile applications (native, web, and
hybrid)

• Frontend for traditional enterprise systems
• Model = data + behavior.
• Isomorphic models: LoopBack, backend DBs, frontend
Model = Data + Behavior
• Rich mobile applications are driven by data.
• Data is created and consumed by mobile devices,
browsers, cloud services, legacy apps, databases, and
other backend systems.
• Mobilizes data through models that represent business
data and behavior.
• Exposes models to mobile apps through REST APIs and
client SDKs.
• You need to interact with the model differently,
depending on the location and type of data.
The big picture
Settings
host: …
port: …
user: …
password: …

initialize

Discovery

Data Source

Connector
Model Definition
id: String,
name: String,
age: Number
define (data)

attachTo

Model
Constructor

• Custom
Methods
• Hooks
• Validations
• Relations

DataAccessObjec
t

mixin (behaviors)

Clou
d
APIs

RDB

strongremoting
•
•

Mobile/J
S SDKs
REST
clients

NoSQ
L
Choose Your Camp and Recipes

1.

Open Models
–

2.

Models with schema
–

3.

“I don’t know my data model yet. Let’s start free form and show me the CRUD APIs!”

“Now I can tell you more information about my data model. Let’s add properties!”

Discover models
–

“Hey, I already have data in relational databases such as Oracle or MySQL. Can the
table schema be my data model?”

4.

Models by instance introspection
–

“Sorry, I’m a NoSQL guy and I have JSON documents for my data. Reverse
engineering?”

5.

Model synchronization with relational databases
–

“Now I have the data model, should I beg the DBA to create/update the tables/columns for
me?”
Recipe 1
I'm mobile developer. Can LoopBack help
me store and load data transparently? I don't
need to worry about the backend or define
the model up front, because my data are
free-form.
Open Models
• Open models are perfect for free-form data or API
mockup

npm install –g strong-cli
slc lb project loopback-models
cd loopback-models
slc lb model form
slc run app
http://localhost:3000/explorer
Explore the APIs
Recipe 2
I want to build a mobile application that will
interact with some backend data. The
structure/types of my data are known. I
would love to see a working REST API and
mobile SDK before I implement the server
side logic.
Define the model
// Load the MongoDB data source
var ds = require('../data-sources/db.js')('mongodb');

// Define a customer model
var Customer = ds.createModel('customer', {
id: {type: Number, id: true},
name: String,
emails: [String],
age: Number},
{strcit: true});
Do some CRUD
Customer.create({
name: 'John1',
emails: ['john@x.com', 'jhon@y.com'],
age: 30
}, function (err, customer1) {
console.log('Customer 1: ', customer1.toObject());
Customer.create({
name: 'John2',
emails: ['john@x.com', 'jhon@y.com'],
age: 30
}, function (err, customer2) {
console.log('Customer 2: ', customer2.toObject());
Customer.findById(customer2.id, function(err, customer3) {
console.log(customer3.toObject());
});
Customer.find({where: {name: 'John1'}, limit: 3}, function(err, customers) {
customers.forEach(function(c) {
console.log(c.toObject());
});
});
});
Recipe 3
I have data in an Oracle or MySQL
database. Can LoopBack figure out the
models and expose them as APIs to my
mobile applications?
Connect to Oracle
var loopback = require('loopback');
var ds = loopback.createDataSource('oracle', {
"host": "demo.strongloop.com",
"port": 1521,
"database": "XE",
"username": "demo",
"password": "L00pBack"
});
Discover and run
var ds = require('../data-sources/db.js')('oracle');
/**
* Discover and build models from INVENTORY table
*/
ds.discoverAndBuildModels('INVENTORY', {visited: {}, owner: 'LOOPBACK',
associations: true}, function (err, models) {
models.Inventory.findOne({}, function (err, inv) {
if (err) {
console.error(err);
return;
}
console.log("nInventory: ", inv);
inv.product(function (err, prod) {
console.log(err);
console.log("nProduct: ", prod);
console.log("n ------------- ");
});
});
Recipe 4
I have JSON documents from REST
services and NoSQL databases. Can
LoopBack introspect my models from them?
Sample JSON document
// Instance JSON document
var user = {
name: 'Joe',
age: 30,
birthday: new Date(),
vip: true,
address: {
street: '1 Main St',
city: 'San Jose',
state: 'CA',
zipcode: '95131',
country: 'US'
},
friends: ['John', 'Mary'],
emails: [
{label: 'work', eid: 'x@sample.com'},
{label: 'home', eid: 'x@home.com'}
],
tags: []
};
Build a model from JSON
var ds = require('../data-sources/db.js')('memory');
// Create a model from the user instance
var User = ds.modelBuilder.buildModelFromInstance('MyUser',
user, {idInjection: true});
User.attachTo(ds);
// Use the model for CRUD
User.create(user, function (err, u1) {
console.log('Created: ', u1.toObject());
User.findById(u1.id, function (err, u2) {
console.log('Found: ', u2.toObject());
});
});
Recipe 5
Now I have defined a LoopBack model, can
LoopBack create or update the relational
database schemas for me?
Model synchronization
• LoopBack provides two ways to synchronize model
definitions with table schemas:
• Auto-migrate: Automatically create or re-create the
table schemas based on the model definitions.
WARNING: An existing table will be dropped if its name

matches the model name.
• Auto-update: Automatically alter the table schemas
based on the model definitions.
Summary
Recipe

Use Case

Model
Strict Mode

Database

Open Model

Taking care of free-form
data

false

NoSQL

Plain Model

Defining a model to
represent data

true or
false

NoSQL or
RDB

Model from
discovery

Consuming existing data
from RDB

true

RDB

Model from
introspection

Consuming JSON data
from NoSQL/REST

false

NoSQL

Model
synchronization

Making sure models are in
sync

true

RDB
What’s Next?
• Try LoopBack
strongloop.com/get-started/

• RTFM
docs.strongloop.com

• Questions?
groups.google.com/forum/#!forum/strongloop

or callback@strongloop.com
26
Recipe 6: Relations
• Models are often connected/related. For example,
– A customer has many orders and each order is owned by a
customer.
– A user can be assigned to one or more roles and a role can have
zero or more users.
– A physician takes care of many patients through appointments. A
patient can see many physicians too.
belongsTo

Order
____________________
___

customer

id: Number
customerId: Number
orderDate: Date

var Order = ds.createModel('Order', {
customerId: Number,
orderDate: Date
});
var Customer = ds.createModel('Customer', {
name: String
});
Order.belongsTo(Customer);
...
order.customer(callback); // Get the customer for the order
order.customer(); // Get the customer for the order synchronously
order.customer(customer); // Set the customer for the order

Customer
_____________________
__
id: Number
name: String
hasMany
Customer
___________________
__

orders

id: Number
name: String

Order
__________________
__
id: Number
customerId: Number
orderDate: Date

var Order = ds.createModel('Order', {
customerId: Number,
orderDate: Date
});
var Customer = ds.createModel('Customer', {
name: String
});

Customer.hasMany(Order, {as: 'orders', foreignKey: 'customerId'});
...
customer.orders(filter, callback); // Find orders for the customer
customer.orders.build(data); // Build a new order
customer.orders.create(data, callback); // Create a new order for the customer
customer.orders.destroyAll(callback); // Remove all orders for the customer
customer.orders.findById(orderId, callback); // Find an order by id
customer.orders.destroy(orderId, callback); // Delete and order by id
hasMany through
physicians
Physician
___________________
__

Appointment
____________________
___

Patient
_________________
__

id: Number
name: String

id: Number
physicianId: Number
patientId: Number
appointmentDate: Date

id: Number
name: String

patients

var Physician = ds.createModel('Physician', {name: String});
var Patient = ds.createModel('Patient', {name: String});
var Appointment = ds.createModel('Appointment', {
physicianId: Number,
patientId: Number,
appointmentDate: Date
});
Physician.hasMany(Patient, {through: Appointment});
Patient.hasMany(Physician, {through: Appointment});
physician.patients(filter, callback); // Find patients for the physician
physician.patients.build(data); // Build a new patient
physician.patients.create(data, callback); // Create a new patient for the physician
physician.patients.destroyAll(callback); // Remove all patients for the physician
physician.patients.add(patient, callback); // Add an patient to the physician
physician.patients.remove(patient, callback); // Remove an patient from the physician
physician.patients.findById(patientId, callback); // Find an patient by id
hasAndBelongsToMany
assemblies

Assembly
___________________
__
id: Number
name: String

AssemblyPart
____________________
___
assemblyId: Number
partId: Number

parts

var Assembly = ds.createModel('Assembly', {name: String});
var Part = ds.createModel('Part', {partNumber: String});
Assembly.hasAndBelongsToMany(Part);
Part.hasAndBelongsToMany(Assembly);
...
assembly.parts(filter, callback); // Find parts for the assembly
assembly.parts.build(data); // Build a new part
assembly.parts.create(data, callback); // Create a new part for the assembly
assembly.parts.add(part, callback); // Add an part to the assembly
assembly.parts.remove(part, callback); // Remove an part from the assembly
assembly.parts.findById(partId, callback); // Find an part by id
assembly.parts.destroy(partId, callback); // Delete and part by id

Part
__________________
__
id: Number
partNumber: String

More Related Content

What's hot

Loopback presentation by tineco
Loopback presentation by tinecoLoopback presentation by tineco
Loopback presentation by tinecoStéphane Guilly
 
Node's Event Loop From the Inside Out - Sam Roberts, IBM
Node's Event Loop From the Inside Out - Sam Roberts, IBMNode's Event Loop From the Inside Out - Sam Roberts, IBM
Node's Event Loop From the Inside Out - Sam Roberts, IBMNodejsFoundation
 
Triangle Node.js DevOps
Triangle Node.js DevOpsTriangle Node.js DevOps
Triangle Node.js DevOpsShubhra Kar
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swaggerTony Tam
 
Web Application Frameworks (WAF)
Web Application Frameworks (WAF)Web Application Frameworks (WAF)
Web Application Frameworks (WAF)Ako Kaman
 
Five Ways to Scale your API Without Touching Your Code
Five Ways to Scale your API Without Touching Your CodeFive Ways to Scale your API Without Touching Your Code
Five Ways to Scale your API Without Touching Your Code3scale
 
Getting Started With Angular
Getting Started With AngularGetting Started With Angular
Getting Started With AngularStormpath
 
Infrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with GitInfrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with GitDanilo Poccia
 
REST API Doc Best Practices
REST API Doc Best PracticesREST API Doc Best Practices
REST API Doc Best PracticesMarta Rauch
 
Will the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir ZukerWill the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir ZukerCodeValue
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and ImprovedTimothy Fisher
 
Building Composable Serverless Apps with IOpipe
Building Composable Serverless Apps with IOpipe Building Composable Serverless Apps with IOpipe
Building Composable Serverless Apps with IOpipe Erica Windisch
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureJeroen Rosenberg
 
Introduction to Usergrid - ApacheCon EU 2014
Introduction to Usergrid - ApacheCon EU 2014Introduction to Usergrid - ApacheCon EU 2014
Introduction to Usergrid - ApacheCon EU 2014David M. Johnson
 
Simple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and SwaggerSimple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and SwaggerLeanIX GmbH
 
Serverless Architecture - A Gentle Overview
Serverless Architecture - A Gentle OverviewServerless Architecture - A Gentle Overview
Serverless Architecture - A Gentle OverviewCodeOps Technologies LLP
 
Open Source Mobile Backend on Cassandra
Open Source Mobile Backend on CassandraOpen Source Mobile Backend on Cassandra
Open Source Mobile Backend on CassandraEd Anuff
 
Full Stack Developer
Full Stack DeveloperFull Stack Developer
Full Stack DeveloperAkbar Uddin
 

What's hot (20)

Loopback presentation by tineco
Loopback presentation by tinecoLoopback presentation by tineco
Loopback presentation by tineco
 
Node's Event Loop From the Inside Out - Sam Roberts, IBM
Node's Event Loop From the Inside Out - Sam Roberts, IBMNode's Event Loop From the Inside Out - Sam Roberts, IBM
Node's Event Loop From the Inside Out - Sam Roberts, IBM
 
Triangle Node.js DevOps
Triangle Node.js DevOpsTriangle Node.js DevOps
Triangle Node.js DevOps
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swagger
 
API Design- Best Practices
API Design-   Best PracticesAPI Design-   Best Practices
API Design- Best Practices
 
Web Application Frameworks (WAF)
Web Application Frameworks (WAF)Web Application Frameworks (WAF)
Web Application Frameworks (WAF)
 
Five Ways to Scale your API Without Touching Your Code
Five Ways to Scale your API Without Touching Your CodeFive Ways to Scale your API Without Touching Your Code
Five Ways to Scale your API Without Touching Your Code
 
Getting Started With Angular
Getting Started With AngularGetting Started With Angular
Getting Started With Angular
 
Infrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with GitInfrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with Git
 
REST API Doc Best Practices
REST API Doc Best PracticesREST API Doc Best Practices
REST API Doc Best Practices
 
Will the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir ZukerWill the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir Zuker
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
Building Composable Serverless Apps with IOpipe
Building Composable Serverless Apps with IOpipe Building Composable Serverless Apps with IOpipe
Building Composable Serverless Apps with IOpipe
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal Architecture
 
Introduction to Usergrid - ApacheCon EU 2014
Introduction to Usergrid - ApacheCon EU 2014Introduction to Usergrid - ApacheCon EU 2014
Introduction to Usergrid - ApacheCon EU 2014
 
Simple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and SwaggerSimple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and Swagger
 
Serverless Architecture - A Gentle Overview
Serverless Architecture - A Gentle OverviewServerless Architecture - A Gentle Overview
Serverless Architecture - A Gentle Overview
 
Open Source Mobile Backend on Cassandra
Open Source Mobile Backend on CassandraOpen Source Mobile Backend on Cassandra
Open Source Mobile Backend on Cassandra
 
Full Stack Developer
Full Stack DeveloperFull Stack Developer
Full Stack Developer
 

Viewers also liked

Getting Started with the Node.js LoopBack APi Framework
Getting Started with the Node.js LoopBack APi FrameworkGetting Started with the Node.js LoopBack APi Framework
Getting Started with the Node.js LoopBack APi FrameworkJimmy Guerrero
 
Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...
Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...
Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...Codemotion Tel Aviv
 
IBM Bluemix for Administrators with Focus on XPages
IBM Bluemix for Administrators with Focus on XPagesIBM Bluemix for Administrators with Focus on XPages
IBM Bluemix for Administrators with Focus on XPagesNiklas Heidloff
 
20150127 RAD스튜디오와 사물인터넷(IoT)
20150127 RAD스튜디오와 사물인터넷(IoT)20150127 RAD스튜디오와 사물인터넷(IoT)
20150127 RAD스튜디오와 사물인터넷(IoT)Devgear
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to dockerJohn Willis
 
Collaborative Line of Business Applications on IBM Bluemix
Collaborative Line of Business Applications on IBM BluemixCollaborative Line of Business Applications on IBM Bluemix
Collaborative Line of Business Applications on IBM BluemixNiklas Heidloff
 
Docker with Cloud Service GCPUG
Docker with Cloud Service  GCPUGDocker with Cloud Service  GCPUG
Docker with Cloud Service GCPUGCaesar Chi
 
Meteor intro-2015
Meteor intro-2015Meteor intro-2015
Meteor intro-2015MeteorJS
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentationscandiweb
 
Meteor, meteoroid and meteorites
Meteor, meteoroid and meteoritesMeteor, meteoroid and meteorites
Meteor, meteoroid and meteoritesJan Del Rosario
 
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014Amazon Web Services
 
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback흥배 최
 
1인개발자가되기전알아야할것들
1인개발자가되기전알아야할것들1인개발자가되기전알아야할것들
1인개발자가되기전알아야할것들Jinsub Jung
 
APIs: The Bridge to IoT
APIs: The Bridge to IoT APIs: The Bridge to IoT
APIs: The Bridge to IoT WSO2
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.jsRyan Anklam
 
Laracon Online: Grid and Flexbox
Laracon Online: Grid and FlexboxLaracon Online: Grid and Flexbox
Laracon Online: Grid and FlexboxRachel Andrew
 

Viewers also liked (20)

Getting Started with the Node.js LoopBack APi Framework
Getting Started with the Node.js LoopBack APi FrameworkGetting Started with the Node.js LoopBack APi Framework
Getting Started with the Node.js LoopBack APi Framework
 
Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...
Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...
Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...
 
IBM Bluemix for Administrators with Focus on XPages
IBM Bluemix for Administrators with Focus on XPagesIBM Bluemix for Administrators with Focus on XPages
IBM Bluemix for Administrators with Focus on XPages
 
Meteor
MeteorMeteor
Meteor
 
20150127 RAD스튜디오와 사물인터넷(IoT)
20150127 RAD스튜디오와 사물인터넷(IoT)20150127 RAD스튜디오와 사물인터넷(IoT)
20150127 RAD스튜디오와 사물인터넷(IoT)
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Collaborative Line of Business Applications on IBM Bluemix
Collaborative Line of Business Applications on IBM BluemixCollaborative Line of Business Applications on IBM Bluemix
Collaborative Line of Business Applications on IBM Bluemix
 
Docker with Cloud Service GCPUG
Docker with Cloud Service  GCPUGDocker with Cloud Service  GCPUG
Docker with Cloud Service GCPUG
 
Android Platform Architecture
Android Platform ArchitectureAndroid Platform Architecture
Android Platform Architecture
 
Will js kill css
Will js kill cssWill js kill css
Will js kill css
 
Meteor intro-2015
Meteor intro-2015Meteor intro-2015
Meteor intro-2015
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentation
 
Meteor, meteoroid and meteorites
Meteor, meteoroid and meteoritesMeteor, meteoroid and meteorites
Meteor, meteoroid and meteorites
 
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
 
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
 
1인개발자가되기전알아야할것들
1인개발자가되기전알아야할것들1인개발자가되기전알아야할것들
1인개발자가되기전알아야할것들
 
APIs: The Bridge to IoT
APIs: The Bridge to IoT APIs: The Bridge to IoT
APIs: The Bridge to IoT
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
Ux is not UI
Ux is not UIUx is not UI
Ux is not UI
 
Laracon Online: Grid and Flexbox
Laracon Online: Grid and FlexboxLaracon Online: Grid and Flexbox
Laracon Online: Grid and Flexbox
 

Similar to Working with LoopBack Models

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Ramp Up Your Web Experiences Using Drupal and Apache Solr
Ramp Up Your Web Experiences Using Drupal and Apache SolrRamp Up Your Web Experiences Using Drupal and Apache Solr
Ramp Up Your Web Experiences Using Drupal and Apache Solrlucenerevolution
 
Advanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareAdvanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareOpevel
 
MongoDB Days UK: Building Apps with the MEAN Stack
MongoDB Days UK: Building Apps with the MEAN StackMongoDB Days UK: Building Apps with the MEAN Stack
MongoDB Days UK: Building Apps with the MEAN StackMongoDB
 
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaSolutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaGuido Schmutz
 
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...confluent
 
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital.AI
 
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...LEDC 2016
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowKarsten Dambekalns
 
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaSolutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaGuido Schmutz
 
Webinar: What's New in Solr 6
Webinar: What's New in Solr 6Webinar: What's New in Solr 6
Webinar: What's New in Solr 6Lucidworks
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsRichard Rodger
 
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Red Hat Developers
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
Cloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload CourseCloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload Coursecloudbase.io
 
Eventually Elasticsearch: Eventual Consistency in the Real World
Eventually Elasticsearch: Eventual Consistency in the Real WorldEventually Elasticsearch: Eventual Consistency in the Real World
Eventually Elasticsearch: Eventual Consistency in the Real WorldBeyondTrees
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101Will Button
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 

Similar to Working with LoopBack Models (20)

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Ramp Up Your Web Experiences Using Drupal and Apache Solr
Ramp Up Your Web Experiences Using Drupal and Apache SolrRamp Up Your Web Experiences Using Drupal and Apache Solr
Ramp Up Your Web Experiences Using Drupal and Apache Solr
 
Advanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareAdvanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshare
 
MongoDB Days UK: Building Apps with the MEAN Stack
MongoDB Days UK: Building Apps with the MEAN StackMongoDB Days UK: Building Apps with the MEAN Stack
MongoDB Days UK: Building Apps with the MEAN Stack
 
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaSolutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
 
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
 
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaSolutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
 
Webinar: What's New in Solr 6
Webinar: What's New in Solr 6Webinar: What's New in Solr 6
Webinar: What's New in Solr 6
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
 
20120816 nodejsdublin
20120816 nodejsdublin20120816 nodejsdublin
20120816 nodejsdublin
 
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
Cloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload CourseCloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload Course
 
Eventually Elasticsearch: Eventual Consistency in the Real World
Eventually Elasticsearch: Eventual Consistency in the Real WorldEventually Elasticsearch: Eventual Consistency in the Real World
Eventually Elasticsearch: Eventual Consistency in the Real World
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 

More from Raymond Feng

Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsRaymond Feng
 
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...Raymond Feng
 
RESTful SCA with Apache Tuscany
RESTful SCA with Apache TuscanyRESTful SCA with Apache Tuscany
RESTful SCA with Apache TuscanyRaymond Feng
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsRaymond Feng
 
Apache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIsApache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIsRaymond Feng
 
OSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyOSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyRaymond Feng
 
OSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache TuscanyOSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache TuscanyRaymond Feng
 

More from Raymond Feng (7)

Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite Applications
 
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
 
RESTful SCA with Apache Tuscany
RESTful SCA with Apache TuscanyRESTful SCA with Apache Tuscany
RESTful SCA with Apache Tuscany
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite Applications
 
Apache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIsApache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIs
 
OSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyOSGi Enablement For Apache Tuscany
OSGi Enablement For Apache Tuscany
 
OSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache TuscanyOSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache Tuscany
 

Recently uploaded

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Recently uploaded (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Working with LoopBack Models

  • 1. Working with LoopBack Models Raymond Feng Co-Founder and Architect
  • 2. About StrongLoop • Founded 2012 • Develop and support… – LoopBack: Open Source Mobile Backend-as-a-Service – StrongOps (formally NodeFly): Real-time performance monitoring – StrongNode: Support for StrongLoop and public Node.js modules • Also maintains and/or contributes to the npm ecosystem: – node-inspector, node-reggie plus over 30 more modules 2
  • 3. The Problem: Apps Need Data • • • • • Not authorized (AAA) XML (Transform) Too much data (Filter) Combine multiple DBs (Join) 50k phones kill DB (Cache)
  • 4. Introducing LoopBack • How can we build scalable Enterprise mobile apps? • Mobile Backend-as-a-Service (e.g. a private Parse you control) • Connects devices and browsers to Enterprise data • Written in Node.js – proven language for mobile backends • Open source – extensible by design • On-premise or on your favorite cloud • Android and iOS SDKs 4
  • 7. LoopBack • Backend for mobile applications (native, web, and hybrid) • Frontend for traditional enterprise systems • Model = data + behavior. • Isomorphic models: LoopBack, backend DBs, frontend
  • 8. Model = Data + Behavior • Rich mobile applications are driven by data. • Data is created and consumed by mobile devices, browsers, cloud services, legacy apps, databases, and other backend systems. • Mobilizes data through models that represent business data and behavior. • Exposes models to mobile apps through REST APIs and client SDKs. • You need to interact with the model differently, depending on the location and type of data.
  • 9. The big picture Settings host: … port: … user: … password: … initialize Discovery Data Source Connector Model Definition id: String, name: String, age: Number define (data) attachTo Model Constructor • Custom Methods • Hooks • Validations • Relations DataAccessObjec t mixin (behaviors) Clou d APIs RDB strongremoting • • Mobile/J S SDKs REST clients NoSQ L
  • 10. Choose Your Camp and Recipes 1. Open Models – 2. Models with schema – 3. “I don’t know my data model yet. Let’s start free form and show me the CRUD APIs!” “Now I can tell you more information about my data model. Let’s add properties!” Discover models – “Hey, I already have data in relational databases such as Oracle or MySQL. Can the table schema be my data model?” 4. Models by instance introspection – “Sorry, I’m a NoSQL guy and I have JSON documents for my data. Reverse engineering?” 5. Model synchronization with relational databases – “Now I have the data model, should I beg the DBA to create/update the tables/columns for me?”
  • 11. Recipe 1 I'm mobile developer. Can LoopBack help me store and load data transparently? I don't need to worry about the backend or define the model up front, because my data are free-form.
  • 12. Open Models • Open models are perfect for free-form data or API mockup npm install –g strong-cli slc lb project loopback-models cd loopback-models slc lb model form slc run app http://localhost:3000/explorer
  • 14. Recipe 2 I want to build a mobile application that will interact with some backend data. The structure/types of my data are known. I would love to see a working REST API and mobile SDK before I implement the server side logic.
  • 15. Define the model // Load the MongoDB data source var ds = require('../data-sources/db.js')('mongodb'); // Define a customer model var Customer = ds.createModel('customer', { id: {type: Number, id: true}, name: String, emails: [String], age: Number}, {strcit: true});
  • 16. Do some CRUD Customer.create({ name: 'John1', emails: ['john@x.com', 'jhon@y.com'], age: 30 }, function (err, customer1) { console.log('Customer 1: ', customer1.toObject()); Customer.create({ name: 'John2', emails: ['john@x.com', 'jhon@y.com'], age: 30 }, function (err, customer2) { console.log('Customer 2: ', customer2.toObject()); Customer.findById(customer2.id, function(err, customer3) { console.log(customer3.toObject()); }); Customer.find({where: {name: 'John1'}, limit: 3}, function(err, customers) { customers.forEach(function(c) { console.log(c.toObject()); }); }); });
  • 17. Recipe 3 I have data in an Oracle or MySQL database. Can LoopBack figure out the models and expose them as APIs to my mobile applications?
  • 18. Connect to Oracle var loopback = require('loopback'); var ds = loopback.createDataSource('oracle', { "host": "demo.strongloop.com", "port": 1521, "database": "XE", "username": "demo", "password": "L00pBack" });
  • 19. Discover and run var ds = require('../data-sources/db.js')('oracle'); /** * Discover and build models from INVENTORY table */ ds.discoverAndBuildModels('INVENTORY', {visited: {}, owner: 'LOOPBACK', associations: true}, function (err, models) { models.Inventory.findOne({}, function (err, inv) { if (err) { console.error(err); return; } console.log("nInventory: ", inv); inv.product(function (err, prod) { console.log(err); console.log("nProduct: ", prod); console.log("n ------------- "); }); });
  • 20. Recipe 4 I have JSON documents from REST services and NoSQL databases. Can LoopBack introspect my models from them?
  • 21. Sample JSON document // Instance JSON document var user = { name: 'Joe', age: 30, birthday: new Date(), vip: true, address: { street: '1 Main St', city: 'San Jose', state: 'CA', zipcode: '95131', country: 'US' }, friends: ['John', 'Mary'], emails: [ {label: 'work', eid: 'x@sample.com'}, {label: 'home', eid: 'x@home.com'} ], tags: [] };
  • 22. Build a model from JSON var ds = require('../data-sources/db.js')('memory'); // Create a model from the user instance var User = ds.modelBuilder.buildModelFromInstance('MyUser', user, {idInjection: true}); User.attachTo(ds); // Use the model for CRUD User.create(user, function (err, u1) { console.log('Created: ', u1.toObject()); User.findById(u1.id, function (err, u2) { console.log('Found: ', u2.toObject()); }); });
  • 23. Recipe 5 Now I have defined a LoopBack model, can LoopBack create or update the relational database schemas for me?
  • 24. Model synchronization • LoopBack provides two ways to synchronize model definitions with table schemas: • Auto-migrate: Automatically create or re-create the table schemas based on the model definitions. WARNING: An existing table will be dropped if its name matches the model name. • Auto-update: Automatically alter the table schemas based on the model definitions.
  • 25. Summary Recipe Use Case Model Strict Mode Database Open Model Taking care of free-form data false NoSQL Plain Model Defining a model to represent data true or false NoSQL or RDB Model from discovery Consuming existing data from RDB true RDB Model from introspection Consuming JSON data from NoSQL/REST false NoSQL Model synchronization Making sure models are in sync true RDB
  • 26. What’s Next? • Try LoopBack strongloop.com/get-started/ • RTFM docs.strongloop.com • Questions? groups.google.com/forum/#!forum/strongloop or callback@strongloop.com 26
  • 27. Recipe 6: Relations • Models are often connected/related. For example, – A customer has many orders and each order is owned by a customer. – A user can be assigned to one or more roles and a role can have zero or more users. – A physician takes care of many patients through appointments. A patient can see many physicians too.
  • 28. belongsTo Order ____________________ ___ customer id: Number customerId: Number orderDate: Date var Order = ds.createModel('Order', { customerId: Number, orderDate: Date }); var Customer = ds.createModel('Customer', { name: String }); Order.belongsTo(Customer); ... order.customer(callback); // Get the customer for the order order.customer(); // Get the customer for the order synchronously order.customer(customer); // Set the customer for the order Customer _____________________ __ id: Number name: String
  • 29. hasMany Customer ___________________ __ orders id: Number name: String Order __________________ __ id: Number customerId: Number orderDate: Date var Order = ds.createModel('Order', { customerId: Number, orderDate: Date }); var Customer = ds.createModel('Customer', { name: String }); Customer.hasMany(Order, {as: 'orders', foreignKey: 'customerId'}); ... customer.orders(filter, callback); // Find orders for the customer customer.orders.build(data); // Build a new order customer.orders.create(data, callback); // Create a new order for the customer customer.orders.destroyAll(callback); // Remove all orders for the customer customer.orders.findById(orderId, callback); // Find an order by id customer.orders.destroy(orderId, callback); // Delete and order by id
  • 30. hasMany through physicians Physician ___________________ __ Appointment ____________________ ___ Patient _________________ __ id: Number name: String id: Number physicianId: Number patientId: Number appointmentDate: Date id: Number name: String patients var Physician = ds.createModel('Physician', {name: String}); var Patient = ds.createModel('Patient', {name: String}); var Appointment = ds.createModel('Appointment', { physicianId: Number, patientId: Number, appointmentDate: Date }); Physician.hasMany(Patient, {through: Appointment}); Patient.hasMany(Physician, {through: Appointment}); physician.patients(filter, callback); // Find patients for the physician physician.patients.build(data); // Build a new patient physician.patients.create(data, callback); // Create a new patient for the physician physician.patients.destroyAll(callback); // Remove all patients for the physician physician.patients.add(patient, callback); // Add an patient to the physician physician.patients.remove(patient, callback); // Remove an patient from the physician physician.patients.findById(patientId, callback); // Find an patient by id
  • 31. hasAndBelongsToMany assemblies Assembly ___________________ __ id: Number name: String AssemblyPart ____________________ ___ assemblyId: Number partId: Number parts var Assembly = ds.createModel('Assembly', {name: String}); var Part = ds.createModel('Part', {partNumber: String}); Assembly.hasAndBelongsToMany(Part); Part.hasAndBelongsToMany(Assembly); ... assembly.parts(filter, callback); // Find parts for the assembly assembly.parts.build(data); // Build a new part assembly.parts.create(data, callback); // Create a new part for the assembly assembly.parts.add(part, callback); // Add an part to the assembly assembly.parts.remove(part, callback); // Remove an part from the assembly assembly.parts.findById(partId, callback); // Find an part by id assembly.parts.destroy(partId, callback); // Delete and part by id Part __________________ __ id: Number partNumber: String