2020-01-21 19:19:18 +00:00
|
|
|
// Copyright IBM Corp. 2013,2019. All Rights Reserved.
|
2016-05-03 22:50:21 +00:00
|
|
|
// Node module: loopback
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-11-15 21:46:23 +00:00
|
|
|
'use strict';
|
2019-10-07 09:45:34 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
const loopback = require('../');
|
2016-11-15 21:46:23 +00:00
|
|
|
|
2014-11-21 02:35:36 +00:00
|
|
|
describe('Memory Connector', function() {
|
2013-07-16 20:39:03 +00:00
|
|
|
it('Create a model using the memory connector', function(done) {
|
|
|
|
// use the built in memory function
|
|
|
|
// to create a memory data source
|
2019-10-07 09:45:34 +00:00
|
|
|
let memory = loopback.memory();
|
2013-07-16 20:39:03 +00:00
|
|
|
|
|
|
|
// or create it using the standard
|
|
|
|
// data source creation api
|
2014-11-21 01:47:47 +00:00
|
|
|
memory = loopback.createDataSource({
|
2016-04-01 09:14:26 +00:00
|
|
|
connector: loopback.Memory,
|
2013-07-16 20:39:03 +00:00
|
|
|
});
|
2014-11-21 01:47:47 +00:00
|
|
|
|
2013-07-16 20:39:03 +00:00
|
|
|
// create a model using the
|
|
|
|
// memory data source
|
2019-10-07 09:45:34 +00:00
|
|
|
const properties = {
|
2013-07-16 20:39:03 +00:00
|
|
|
name: String,
|
2016-04-01 09:14:26 +00:00
|
|
|
price: Number,
|
2013-07-16 20:39:03 +00:00
|
|
|
};
|
2014-11-21 01:47:47 +00:00
|
|
|
|
2019-10-07 09:45:34 +00:00
|
|
|
const Product = memory.createModel('product', properties);
|
2014-11-21 01:47:47 +00:00
|
|
|
|
2013-07-16 20:39:03 +00:00
|
|
|
Product.create([
|
2016-11-15 21:46:23 +00:00
|
|
|
{name: 'apple', price: 0.79},
|
|
|
|
{name: 'pear', price: 1.29},
|
|
|
|
{name: 'orange', price: 0.59},
|
2013-07-16 20:39:03 +00:00
|
|
|
], count);
|
2014-11-21 01:47:47 +00:00
|
|
|
|
2013-07-16 20:39:03 +00:00
|
|
|
function count() {
|
2014-11-21 02:35:36 +00:00
|
|
|
Product.count(function(err, count) {
|
2013-07-16 20:39:03 +00:00
|
|
|
assert.equal(count, 3);
|
2016-05-05 04:09:06 +00:00
|
|
|
|
2013-07-16 20:39:03 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-11-21 01:47:47 +00:00
|
|
|
});
|