1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | const DataSource = require('../../loopback-datasource-juggler').DataSource;
|
9 | const ModelBuilder = require('../../loopback-datasource-juggler').ModelBuilder;
|
10 | const introspectType = require('../lib/introspection')(ModelBuilder);
|
11 |
|
12 | const ds = new DataSource('memory');
|
13 |
|
14 |
|
15 | const Application = ds.createModel('Schemaless', {}, {strict: false});
|
16 |
|
17 | const application = {
|
18 | owner: 'rfeng',
|
19 | name: 'MyApp1',
|
20 | description: 'My first app',
|
21 | pushSettings: [
|
22 | {'platform': 'apns',
|
23 | 'apns': {
|
24 | 'pushOptions': {
|
25 | 'gateway': 'gateway.sandbox.push.apple.com',
|
26 | 'cert': 'credentials/apns_cert_dev.pem',
|
27 | 'key': 'credentials/apns_key_dev.pem',
|
28 | },
|
29 |
|
30 | 'feedbackOptions': {
|
31 | 'gateway': 'feedback.sandbox.push.apple.com',
|
32 | 'cert': 'credentials/apns_cert_dev.pem',
|
33 | 'key': 'credentials/apns_key_dev.pem',
|
34 | 'batchFeedback': true,
|
35 | 'interval': 300,
|
36 | },
|
37 | }},
|
38 | ]};
|
39 |
|
40 | console.log(new Application(application).toObject());
|
41 |
|
42 | Application.create(application, function(err, app1) {
|
43 | console.log('Created: ', app1.toObject());
|
44 | Application.findById(app1.id, function(err, app2) {
|
45 | console.log('Found: ', app2.toObject());
|
46 | });
|
47 | });
|
48 |
|
49 |
|
50 | const user = {
|
51 | name: 'Joe',
|
52 | age: 30,
|
53 | birthday: new Date(),
|
54 | vip: true,
|
55 | address: {
|
56 | street: '1 Main St',
|
57 | city: 'San Jose',
|
58 | state: 'CA',
|
59 | zipcode: '95131',
|
60 | country: 'US',
|
61 | },
|
62 | friends: ['John', 'Mary'],
|
63 | emails: [
|
64 | {label: 'work', id: 'x@sample.com'},
|
65 | {label: 'home', id: 'x@home.com'},
|
66 | ],
|
67 | tags: [],
|
68 | };
|
69 |
|
70 |
|
71 | const schema = introspectType(user);
|
72 |
|
73 |
|
74 | const User = ds.createModel('User', schema, {idInjection: true});
|
75 |
|
76 |
|
77 | const obj = new User(user);
|
78 |
|
79 | console.log(obj.toObject());
|
80 |
|
81 | User.create(user, function(err, u1) {
|
82 | console.log('Created: ', u1.toObject());
|
83 | User.findById(u1.id, function(err, u2) {
|
84 | console.log('Found: ', u2.toObject());
|
85 | });
|
86 | });
|