Merge pull request #88 from strongloop/feature/update-deps
Update deps and fix styles
This commit is contained in:
commit
9996e39fd2
1
index.js
1
index.js
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var SG = require('strong-globalize');
|
||||
SG.SetRootDir(__dirname);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ module.exports = BinaryPacker;
|
|||
* - Date
|
||||
*/
|
||||
function BinaryPacker() {
|
||||
this._packer = msgpack({ forceFloat64: true });
|
||||
this._packer = msgpack({forceFloat64: true});
|
||||
this._packer.register(1, Date, encodeDate, decodeDate);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var SG = require('strong-globalize');
|
||||
var g = SG();
|
||||
var debug = require('debug')('loopback:connector');
|
||||
|
@ -49,7 +50,7 @@ Connector.prototype.getTypes = function() {
|
|||
* @returns {Function} The default type for ID
|
||||
*/
|
||||
Connector.prototype.getDefaultIdType = function(prop) {
|
||||
/*jshint unused:false */
|
||||
/* jshint unused:false */
|
||||
return String;
|
||||
};
|
||||
|
||||
|
@ -278,6 +279,3 @@ Connector.defineAliases = function(cls, methodOrPropertyName, aliases) {
|
|||
*/
|
||||
Connector.defineAliases(Connector.prototype, 'execute', ['command', 'query']);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var assert = require('assert');
|
||||
var PLACEHOLDER = '?';
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var SG = require('strong-globalize');
|
||||
var g = SG();
|
||||
|
||||
|
@ -121,11 +122,10 @@ SQLConnector.prototype.isActual = function(models, cb) {
|
|||
return cb && cb(err);
|
||||
}
|
||||
var actual = (changes.length === 0);
|
||||
cb && cb(null, actual);
|
||||
if (cb) cb(null, actual);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
SQLConnector.prototype.getAddModifyColumns = function(model, fields) {
|
||||
throw new Error(g.f('{{getAddModifyColumns()}} must be implemented by the connector'));
|
||||
};
|
||||
|
@ -922,7 +922,7 @@ SQLConnector.prototype._executeAlteringQuery = function(model, sql, params, opti
|
|||
var self = this;
|
||||
this.execute(sql, params, options, function(err, info) {
|
||||
var affectedRows = self.getCountForAffectedRows(model, info);
|
||||
cb(err, { count: affectedRows });
|
||||
cb(err, {count: affectedRows});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1468,7 +1468,7 @@ SQLConnector.prototype.find = function(model, id, options, cb) {
|
|||
var idName = this.idName(model);
|
||||
where[idName] = id;
|
||||
|
||||
var filter = { limit: 1, offset: 0, order: idName, where: where };
|
||||
var filter = {limit: 1, offset: 0, order: idName, where: where};
|
||||
return this.all(model, filter, options, function(err, results) {
|
||||
cb(err, (results && results[0]) || null);
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var assert = require('assert');
|
||||
var util = require('util');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
@ -68,7 +69,7 @@ Transaction.begin = function(connector, options, cb) {
|
|||
options = {};
|
||||
}
|
||||
if (typeof options === 'string') {
|
||||
options = { isolationLevel: options };
|
||||
options = {isolationLevel: options};
|
||||
}
|
||||
var isolationLevel = options.isolationLevel || Transaction.READ_COMMITTED;
|
||||
assert(isolationLevel === Transaction.SERIALIZABLE ||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var Promise = require('bluebird');
|
||||
|
||||
exports.createPromiseCallback = createPromiseCallback;
|
||||
|
|
12
package.json
12
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "loopback-connector",
|
||||
"version": "3.0.0",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"description": "Building blocks for LoopBack connectors",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
|
@ -22,17 +22,17 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"async": "^1.0.0",
|
||||
"async": "^2.1.5",
|
||||
"bluebird": "^3.4.6",
|
||||
"debug": "^2.2.0",
|
||||
"msgpack5": "^3.4.1",
|
||||
"strong-globalize": "^2.5.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "~2.3.0",
|
||||
"eslint": "^2.7.0",
|
||||
"eslint-config-loopback": "^1.0.0",
|
||||
"chai": "~3.5.0",
|
||||
"eslint": "^3.17.1",
|
||||
"eslint-config-loopback": "^8.0.0",
|
||||
"loopback-datasource-juggler": "^3.0.0",
|
||||
"mocha": "^2.2.5"
|
||||
"mocha": "^3.2.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var expect = require('chai').expect;
|
||||
var testConnector = require('./connectors/test-sql-connector');
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ describe('BinaryPacker', function() {
|
|||
describe('roundtrip', function() {
|
||||
var TEST_CASES = {
|
||||
String: 'a-value',
|
||||
Object: { a: 1, b: 2 },
|
||||
Object: {a: 1, b: 2},
|
||||
Buffer: new Buffer([1, 2, 3]),
|
||||
Date: new Date('2016-08-03T11:53:03.470Z'),
|
||||
Integer: 12345,
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
/*
|
||||
* A mockup connector that extends SQL connector
|
||||
*/
|
||||
|
@ -102,7 +103,7 @@ TestConnector.prototype._buildLimit = function(model, limit, offset) {
|
|||
|
||||
TestConnector.prototype.applyPagination =
|
||||
function(model, stmt, filter) {
|
||||
/*jshint unused:false */
|
||||
/* jshint unused:false */
|
||||
var limitClause = this._buildLimit(model, filter.limit,
|
||||
filter.offset || filter.skip);
|
||||
return stmt.merge(limitClause);
|
||||
|
@ -155,7 +156,7 @@ TestConnector.prototype._buildLimit = function(model, limit, offset) {
|
|||
|
||||
TestConnector.prototype.applyPagination =
|
||||
function(model, stmt, filter) {
|
||||
/*jshint unused:false */
|
||||
/* jshint unused:false */
|
||||
var limitClause = this._buildLimit(model, filter.limit,
|
||||
filter.offset || filter.skip);
|
||||
return stmt.merge(limitClause);
|
||||
|
@ -215,7 +216,7 @@ TestConnector.prototype.executeSQL = function(sql, params, options, callback) {
|
|||
if (sql.indexOf('INSERT') === 0) {
|
||||
transaction.connection.data[model] =
|
||||
transaction.connection.data[model] || [];
|
||||
transaction.connection.data[model].push({ sql: sql, params: params });
|
||||
transaction.connection.data[model].push({sql: sql, params: params});
|
||||
debug('INSERT', transaction.connection.data, sql,
|
||||
transaction.connection.name);
|
||||
callback(null, 1);
|
||||
|
@ -227,7 +228,7 @@ TestConnector.prototype.executeSQL = function(sql, params, options, callback) {
|
|||
} else {
|
||||
if (sql.indexOf('INSERT') === 0) {
|
||||
this.data[model] = this.data[model] || [];
|
||||
this.data[model].push({ sql: sql, params: params });
|
||||
this.data[model].push({sql: sql, params: params});
|
||||
debug('INSERT', this.data, sql);
|
||||
callback(null, 1);
|
||||
} else {
|
||||
|
|
|
@ -37,7 +37,7 @@ describe('JSONStringPacker', function() {
|
|||
describe('roundtrip', function() {
|
||||
var TEST_CASES = {
|
||||
String: 'a-value',
|
||||
Object: { a: 1, b: 2 },
|
||||
Object: {a: 1, b: 2},
|
||||
Buffer: new Buffer([1, 2, 3]),
|
||||
Date: new Date('2016-08-03T11:53:03.470Z'),
|
||||
Integer: 12345,
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var assert = require('assert');
|
||||
var connector = require('../');
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var expect = require('chai').expect;
|
||||
var SQLConnector = require('../lib/sql');
|
||||
var ParameterizedSQL = SQLConnector.ParameterizedSQL;
|
||||
|
@ -41,7 +42,7 @@ describe('sql connector', function() {
|
|||
},
|
||||
address: String,
|
||||
},
|
||||
{ testdb: { table: 'CUSTOMER' }});
|
||||
{testdb: {table: 'CUSTOMER'}});
|
||||
});
|
||||
|
||||
it('should map table name', function() {
|
||||
|
@ -94,7 +95,7 @@ describe('sql connector', function() {
|
|||
});
|
||||
|
||||
it('builds where', function() {
|
||||
var where = connector.buildWhere('customer', { name: 'John' });
|
||||
var where = connector.buildWhere('customer', {name: 'John'});
|
||||
expect(where.toJSON()).to.eql({
|
||||
sql: 'WHERE `NAME`=?',
|
||||
params: ['John'],
|
||||
|
@ -102,7 +103,7 @@ describe('sql connector', function() {
|
|||
});
|
||||
|
||||
it('builds where with null', function() {
|
||||
var where = connector.buildWhere('customer', { name: null });
|
||||
var where = connector.buildWhere('customer', {name: null});
|
||||
expect(where.toJSON()).to.eql({
|
||||
sql: 'WHERE `NAME` IS NULL',
|
||||
params: [],
|
||||
|
@ -110,7 +111,7 @@ describe('sql connector', function() {
|
|||
});
|
||||
|
||||
it('builds where with inq', function() {
|
||||
var where = connector.buildWhere('customer', { name: { inq: ['John', 'Mary'] }});
|
||||
var where = connector.buildWhere('customer', {name: {inq: ['John', 'Mary']}});
|
||||
expect(where.toJSON()).to.eql({
|
||||
sql: 'WHERE `NAME` IN (?,?)',
|
||||
params: ['John', 'Mary'],
|
||||
|
@ -119,7 +120,7 @@ describe('sql connector', function() {
|
|||
|
||||
it('builds where with or', function() {
|
||||
var where = connector.buildWhere('customer',
|
||||
{ or: [{ name: 'John' }, { name: 'Mary' }] });
|
||||
{or: [{name: 'John'}, {name: 'Mary'}]});
|
||||
expect(where.toJSON()).to.eql({
|
||||
sql: 'WHERE (`NAME`=?) OR (`NAME`=?)',
|
||||
params: ['John', 'Mary'],
|
||||
|
@ -128,7 +129,7 @@ describe('sql connector', function() {
|
|||
|
||||
it('builds where with and', function() {
|
||||
var where = connector.buildWhere('customer',
|
||||
{ and: [{ name: 'John' }, { vip: true }] });
|
||||
{and: [{name: 'John'}, {vip: true}]});
|
||||
expect(where.toJSON()).to.eql({
|
||||
sql: 'WHERE (`NAME`=?) AND (`VIP`=?)',
|
||||
params: ['John', true],
|
||||
|
@ -209,7 +210,7 @@ describe('sql connector', function() {
|
|||
|
||||
it('builds where with nesting and/or', function() {
|
||||
var where = connector.buildWhere('customer',
|
||||
{ and: [{ name: 'John' }, { or: [{ vip: true }, { address: null }] }] });
|
||||
{and: [{name: 'John'}, {or: [{vip: true}, {address: null}]}]});
|
||||
expect(where.toJSON()).to.eql({
|
||||
sql: 'WHERE (`NAME`=?) AND ((`VIP`=?) OR (`ADDRESS` IS NULL))',
|
||||
params: ['John', true],
|
||||
|
@ -233,17 +234,17 @@ describe('sql connector', function() {
|
|||
|
||||
it('builds fields for columns', function() {
|
||||
var fields = connector.buildFields('customer',
|
||||
{ name: 'John', vip: true, unknown: 'Random' });
|
||||
{name: 'John', vip: true, unknown: 'Random'});
|
||||
expect(fields.names).to.eql(['`NAME`', '`VIP`']);
|
||||
expect(fields.columnValues[0].toJSON()).to.eql(
|
||||
{ sql: '?', params: ['John'] });
|
||||
{sql: '?', params: ['John']});
|
||||
expect(fields.columnValues[1].toJSON()).to.eql(
|
||||
{ sql: '?', params: [true] });
|
||||
{sql: '?', params: [true]});
|
||||
});
|
||||
|
||||
it('builds fields for UPDATE without ids', function() {
|
||||
var fields = connector.buildFieldsForUpdate('customer',
|
||||
{ name: 'John', vip: true });
|
||||
{name: 'John', vip: true});
|
||||
expect(fields.toJSON()).to.eql({
|
||||
sql: 'SET `VIP`=?',
|
||||
params: [true],
|
||||
|
@ -252,7 +253,7 @@ describe('sql connector', function() {
|
|||
|
||||
it('builds fields for UPDATE with ids', function() {
|
||||
var fields = connector.buildFieldsForUpdate('customer',
|
||||
{ name: 'John', vip: true }, false);
|
||||
{name: 'John', vip: true}, false);
|
||||
expect(fields.toJSON()).to.eql({
|
||||
sql: 'SET `NAME`=?,`VIP`=?',
|
||||
params: ['John', true],
|
||||
|
@ -265,22 +266,22 @@ describe('sql connector', function() {
|
|||
});
|
||||
|
||||
it('builds column names with true fields filter for SELECT', function() {
|
||||
var cols = connector.buildColumnNames('customer', { fields: { name: true }});
|
||||
var cols = connector.buildColumnNames('customer', {fields: {name: true}});
|
||||
expect(cols).to.eql('`NAME`');
|
||||
});
|
||||
|
||||
it('builds column names with false fields filter for SELECT', function() {
|
||||
var cols = connector.buildColumnNames('customer', { fields: { name: false }});
|
||||
var cols = connector.buildColumnNames('customer', {fields: {name: false}});
|
||||
expect(cols).to.eql('`VIP`,`ADDRESS`');
|
||||
});
|
||||
|
||||
it('builds column names with array fields filter for SELECT', function() {
|
||||
var cols = connector.buildColumnNames('customer', { fields: ['name'] });
|
||||
var cols = connector.buildColumnNames('customer', {fields: ['name']});
|
||||
expect(cols).to.eql('`NAME`');
|
||||
});
|
||||
|
||||
it('builds DELETE', function() {
|
||||
var sql = connector.buildDelete('customer', { name: 'John' });
|
||||
var sql = connector.buildDelete('customer', {name: 'John'});
|
||||
expect(sql.toJSON()).to.eql({
|
||||
sql: 'DELETE FROM `CUSTOMER` WHERE `NAME`=$1',
|
||||
params: ['John'],
|
||||
|
@ -288,7 +289,7 @@ describe('sql connector', function() {
|
|||
});
|
||||
|
||||
it('builds UPDATE', function() {
|
||||
var sql = connector.buildUpdate('customer', { name: 'John' }, { vip: false });
|
||||
var sql = connector.buildUpdate('customer', {name: 'John'}, {vip: false});
|
||||
expect(sql.toJSON()).to.eql({
|
||||
sql: 'UPDATE `CUSTOMER` SET `VIP`=$1 WHERE `NAME`=$2',
|
||||
params: [false, 'John'],
|
||||
|
@ -297,7 +298,7 @@ describe('sql connector', function() {
|
|||
|
||||
it('builds SELECT', function() {
|
||||
var sql = connector.buildSelect('customer',
|
||||
{ order: 'name', limit: 5, where: { name: 'John' }});
|
||||
{order: 'name', limit: 5, where: {name: 'John'}});
|
||||
expect(sql.toJSON()).to.eql({
|
||||
sql: 'SELECT `NAME`,`VIP`,`ADDRESS` FROM `CUSTOMER`' +
|
||||
' WHERE `NAME`=$1 ORDER BY `NAME` LIMIT 5',
|
||||
|
@ -306,7 +307,7 @@ describe('sql connector', function() {
|
|||
});
|
||||
|
||||
it('builds INSERT', function() {
|
||||
var sql = connector.buildInsert('customer', { name: 'John', vip: true });
|
||||
var sql = connector.buildInsert('customer', {name: 'John', vip: true});
|
||||
expect(sql.toJSON()).to.eql({
|
||||
sql: 'INSERT INTO `CUSTOMER`(`NAME`,`VIP`) VALUES($1,$2)',
|
||||
params: ['John', true],
|
||||
|
@ -316,49 +317,49 @@ describe('sql connector', function() {
|
|||
it('normalizes a SQL statement from string', function() {
|
||||
var sql = 'SELECT * FROM `CUSTOMER`';
|
||||
var stmt = new ParameterizedSQL(sql);
|
||||
expect(stmt.toJSON()).to.eql({ sql: sql, params: [] });
|
||||
expect(stmt.toJSON()).to.eql({sql: sql, params: []});
|
||||
});
|
||||
|
||||
it('normalizes a SQL statement from object without params', function() {
|
||||
var sql = { sql: 'SELECT * FROM `CUSTOMER`' };
|
||||
var sql = {sql: 'SELECT * FROM `CUSTOMER`'};
|
||||
var stmt = new ParameterizedSQL(sql);
|
||||
expect(stmt.toJSON()).to.eql({ sql: sql.sql, params: [] });
|
||||
expect(stmt.toJSON()).to.eql({sql: sql.sql, params: []});
|
||||
});
|
||||
|
||||
it('normalizes a SQL statement from object with params', function() {
|
||||
var sql =
|
||||
{ sql: 'SELECT * FROM `CUSTOMER` WHERE `NAME`=?', params: ['John'] };
|
||||
{sql: 'SELECT * FROM `CUSTOMER` WHERE `NAME`=?', params: ['John']};
|
||||
var stmt = new ParameterizedSQL(sql);
|
||||
expect(stmt.toJSON()).to.eql({ sql: sql.sql, params: ['John'] });
|
||||
expect(stmt.toJSON()).to.eql({sql: sql.sql, params: ['John']});
|
||||
});
|
||||
|
||||
it('should throw if the statement is not a string or object', function() {
|
||||
expect(function() {
|
||||
/*jshint unused:false */
|
||||
/* jshint unused:false */
|
||||
var stmt = new ParameterizedSQL(true);
|
||||
}).to.throw('sql must be a string');
|
||||
});
|
||||
|
||||
it('concats SQL statements', function() {
|
||||
var stmt1 = { sql: 'SELECT * from `CUSTOMER`' };
|
||||
var where = { sql: 'WHERE `NAME`=?', params: ['John'] };
|
||||
var stmt1 = {sql: 'SELECT * from `CUSTOMER`'};
|
||||
var where = {sql: 'WHERE `NAME`=?', params: ['John']};
|
||||
stmt1 = ParameterizedSQL.append(stmt1, where);
|
||||
expect(stmt1.toJSON()).to.eql(
|
||||
{ sql: 'SELECT * from `CUSTOMER` WHERE `NAME`=?', params: ['John'] });
|
||||
{sql: 'SELECT * from `CUSTOMER` WHERE `NAME`=?', params: ['John']});
|
||||
});
|
||||
|
||||
it('concats string SQL statements', function() {
|
||||
var stmt1 = 'SELECT * from `CUSTOMER`';
|
||||
var where = { sql: 'WHERE `NAME`=?', params: ['John'] };
|
||||
var where = {sql: 'WHERE `NAME`=?', params: ['John']};
|
||||
stmt1 = ParameterizedSQL.append(stmt1, where);
|
||||
expect(stmt1.toJSON()).to.eql(
|
||||
{ sql: 'SELECT * from `CUSTOMER` WHERE `NAME`=?', params: ['John'] });
|
||||
{sql: 'SELECT * from `CUSTOMER` WHERE `NAME`=?', params: ['John']});
|
||||
});
|
||||
|
||||
it('should throw if params does not match placeholders', function() {
|
||||
expect(function() {
|
||||
var stmt1 = 'SELECT * from `CUSTOMER`';
|
||||
var where = { sql: 'WHERE `NAME`=?', params: ['John', 'Mary'] };
|
||||
var where = {sql: 'WHERE `NAME`=?', params: ['John', 'Mary']};
|
||||
stmt1 = ParameterizedSQL.append(stmt1, where);
|
||||
}).to.throw('must match the number of params');
|
||||
});
|
||||
|
@ -374,7 +375,7 @@ describe('sql connector', function() {
|
|||
|
||||
it('should allow execute(sql, params, options, callback)', function(done) {
|
||||
connector.execute('SELECT * FROM `CUSTOMER` WHERE `NAME`=$1',
|
||||
['xyz'], { transaction: true }, done);
|
||||
['xyz'], {transaction: true}, done);
|
||||
});
|
||||
|
||||
it('should throw if params is not an array for execute()', function() {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
var Transaction = require('../index').Transaction;
|
||||
|
||||
var expect = require('chai').expect;
|
||||
|
@ -18,14 +19,14 @@ describe('transactions', function() {
|
|||
});
|
||||
db.once('connected', function() {
|
||||
Post = db.define('PostTX', {
|
||||
title: { type: String, length: 255, index: true },
|
||||
content: { type: String },
|
||||
title: {type: String, length: 255, index: true},
|
||||
content: {type: String},
|
||||
});
|
||||
Review = db.define('ReviewTX', {
|
||||
author: String,
|
||||
content: { type: String },
|
||||
content: {type: String},
|
||||
});
|
||||
Post.hasMany(Review, { as: 'reviews', foreignKey: 'postId' });
|
||||
Post.hasMany(Review, {as: 'reviews', foreignKey: 'postId'});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -61,7 +62,7 @@ describe('transactions', function() {
|
|||
next();
|
||||
});
|
||||
currentTx = tx;
|
||||
Post.create(post, { transaction: tx, model: 'Post' },
|
||||
Post.create(post, {transaction: tx, model: 'Post'},
|
||||
function(err, p) {
|
||||
if (err) {
|
||||
done(err);
|
||||
|
@ -69,7 +70,7 @@ describe('transactions', function() {
|
|||
p.reviews.create({
|
||||
author: 'John',
|
||||
content: 'Review for ' + p.title,
|
||||
}, { transaction: tx, model: 'Review' },
|
||||
}, {transaction: tx, model: 'Review'},
|
||||
function(err, c) {
|
||||
done(err);
|
||||
});
|
||||
|
@ -83,11 +84,11 @@ describe('transactions', function() {
|
|||
// records to equal to the count
|
||||
function expectToFindPosts(where, count, inTx) {
|
||||
return function(done) {
|
||||
var options = { model: 'Post' };
|
||||
var options = {model: 'Post'};
|
||||
if (inTx) {
|
||||
options.transaction = currentTx;
|
||||
}
|
||||
Post.find({ where: where }, options,
|
||||
Post.find({where: where}, options,
|
||||
function(err, posts) {
|
||||
if (err) return done(err);
|
||||
expect(posts.length).to.be.eql(count);
|
||||
|
@ -109,7 +110,7 @@ describe('transactions', function() {
|
|||
}
|
||||
|
||||
describe('commit', function() {
|
||||
var post = { title: 't1', content: 'c1' };
|
||||
var post = {title: 't1', content: 'c1'};
|
||||
before(createPostInTx(post));
|
||||
|
||||
it('should not see the uncommitted insert', expectToFindPosts(post, 0));
|
||||
|
@ -140,7 +141,7 @@ describe('transactions', function() {
|
|||
db.connector.data = {};
|
||||
});
|
||||
|
||||
var post = { title: 't2', content: 'c2' };
|
||||
var post = {title: 't2', content: 'c2'};
|
||||
before(createPostInTx(post));
|
||||
|
||||
it('should not see the uncommitted insert', expectToFindPosts(post, 0));
|
||||
|
@ -171,12 +172,12 @@ describe('transactions', function() {
|
|||
db.connector.data = {};
|
||||
});
|
||||
|
||||
var post = { title: 't3', content: 'c3' };
|
||||
var post = {title: 't3', content: 'c3'};
|
||||
before(createPostInTx(post, 50));
|
||||
|
||||
it('should report timeout', function(done) {
|
||||
setTimeout(function() {
|
||||
Post.find({ where: { title: 't3' }}, { transaction: currentTx },
|
||||
Post.find({where: {title: 't3'}}, {transaction: currentTx},
|
||||
function(err, posts) {
|
||||
if (err) return done(err);
|
||||
expect(posts.length).to.be.eql(1);
|
||||
|
|
Loading…
Reference in New Issue