2016-05-03 22:50:21 +00:00
|
|
|
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
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
|
|
|
|
var memory = loopback.memory();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
var properties = {
|
|
|
|
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
|
|
|
|
2013-07-16 20:39:03 +00:00
|
|
|
var Product = memory.createModel('product', properties);
|
2014-11-21 01:47:47 +00:00
|
|
|
|
2013-07-16 20:39:03 +00:00
|
|
|
Product.create([
|
2016-04-01 09:14:26 +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
|
|
|
});
|