loopback/test/memory.test.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

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
'use strict';
const assert = require('assert');
const loopback = require('../');
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
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({
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
const properties = {
2013-07-16 20:39:03 +00:00
name: String,
price: Number,
2013-07-16 20:39:03 +00:00
};
2014-11-21 01:47:47 +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([
{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);
2013-07-16 20:39:03 +00:00
done();
});
}
});
2014-11-21 01:47:47 +00:00
});