-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathmodel.js
47 lines (41 loc) · 1.36 KB
/
model.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright IBM Corp. 2013,2019. All Rights Reserved.
// Node module: loopback-connector-postgresql
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
'use strict';
const SG = require('strong-globalize');
const g = SG();
const DataSource = require('loopback-datasource-juggler').DataSource;
const config = require('rc')('loopback', {dev: {postgresql: {}}}).dev.postgresql;
const ds = new DataSource(require('../'), config);
// Define a account model
const Account = ds.createModel('account', {
name: String,
emails: [String],
age: Number},
{strict: true});
ds.automigrate('account', function(err) {
// Create two instances
Account.create({
name: 'John1',
emails: ['john@x.com', 'jhon@y.com'],
age: 30,
}, function(err, account1) {
console.log('Account 1: ', account1.toObject());
Account.create({
name: 'John2',
emails: ['john@x.com', 'jhon@y.com'],
age: 30,
}, function(err, account2) {
console.log('Account 2: ', account2.toObject());
Account.findById(account2.id, function(err, account3) {
console.log(account3.toObject());
});
Account.find({where: {name: 'John1'}, limit: 3}, function(err, accounts) {
accounts.forEach(function(c) {
console.log(c.toObject());
});
});
});
});
});