Auto-update by eslint --fix

This commit is contained in:
Amir Jafarian 2016-04-09 14:35:52 -04:00
parent 9061026027
commit fc33ced470
8 changed files with 108 additions and 108 deletions

View File

@ -61,7 +61,7 @@ Connector.prototype.getMetadata = function() {
types: this.getTypes(),
defaultIdType: this.getDefaultIdType(),
isRelational: this.isRelational(),
schemaForSettings: {}
schemaForSettings: {},
};
}
return this._metadata;
@ -259,7 +259,7 @@ Connector.defineAliases = function(cls, methodOrPropertyName, aliases) {
Object.defineProperty(cls, alias, {
get: function() {
return this[methodOrPropertyName];
}
},
});
}
});

View File

@ -55,7 +55,7 @@ ParameterizedSQL.prototype.merge = function(ps, separator) {
ParameterizedSQL.prototype.toJSON = function() {
return {
sql: this.sql,
params: this.params
params: this.params,
};
};

View File

@ -402,13 +402,13 @@ SQLConnector.prototype.execute = function(sql, params, options, callback) {
var context = {
req: {
sql: sql,
params: params
params: params,
},
options: options
options: options,
};
this.notifyObserversAround('execute', context, function(context, done) {
self.executeSQL(context.req.sql, context.req.params, context.options, function(err, info) {
if(err){
if (err) {
debug('Error: %j %j %j', err, context.req.sql, context.req.params);
}
@ -493,7 +493,7 @@ SQLConnector.prototype.exists = function(model, id, options, cb) {
selectStmt = this.applyPagination(model, selectStmt, {
limit: 1,
offset: 0,
order: [idName]
order: [idName],
});
selectStmt = this.parameterize(selectStmt);
@ -688,7 +688,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 });
});
};
@ -826,7 +826,7 @@ SQLConnector.prototype._buildWhere = function(model, where) {
}
stmt.merge({
sql: branches.join(' ' + key.toUpperCase() + ' '),
params: branchParams
params: branchParams,
});
whereStmts.push(stmt);
continue;
@ -895,7 +895,7 @@ SQLConnector.prototype._buildWhere = function(model, where) {
} else {
stmt.merge({
sql: columnName + '=?',
params: [columnValue]
params: [columnValue],
});
}
}
@ -910,7 +910,7 @@ SQLConnector.prototype._buildWhere = function(model, where) {
}
var whereStmt = new ParameterizedSQL({
sql: sqls.join(' AND '),
params: params
params: params,
});
return whereStmt;
};
@ -978,8 +978,8 @@ SQLConnector.prototype._buildFieldsForKeys = function(model, data, keys, exclude
var fields = {
names: [], // field names
columnValues: [], // an array of ParameterizedSQL
properties: [] // model properties
};
properties: [], // model properties
};
for (var i = 0, n = keys.length; i < n; i++) {
var key = keys[i];
var p = props[key];
@ -1232,7 +1232,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);
});

View File

@ -30,7 +30,7 @@ Transaction.hookTypes = {
AFTER_COMMIT: 'after commit',
BEFORE_ROLLBACK: 'before rollback',
AFTER_ROLLBACK: 'after rollback',
TIMEOUT: 'timeout'
TIMEOUT: 'timeout',
};
/**
@ -63,7 +63,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 ||

View File

@ -4,7 +4,7 @@ var testConnector = require('./connectors/test-sql-connector');
var juggler = require('loopback-datasource-juggler');
var ds = new juggler.DataSource({
connector: testConnector,
debug: true
debug: true,
});
describe('sql connector', function() {

View File

@ -210,7 +210,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);
@ -223,7 +223,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 {

View File

@ -6,7 +6,7 @@ var testConnector = require('./connectors/test-sql-connector');
var juggler = require('loopback-datasource-juggler');
var ds = new juggler.DataSource({
connector: testConnector,
debug: true
debug: true,
});
var connector;
var Customer;
@ -24,17 +24,17 @@ describe('sql connector', function() {
testdb: {
column: 'NAME',
dataType: 'VARCHAR',
dataLength: 32
}
dataLength: 32,
},
}, vip: {
type: Boolean,
testdb: {
column: 'VIP'
}
type: Boolean,
testdb: {
column: 'VIP',
},
},
address: String,
},
address: String
},
{testdb: {table: 'CUSTOMER'}});
{ testdb: { table: 'CUSTOMER' }});
});
it('should map table name', function() {
@ -52,7 +52,7 @@ describe('sql connector', function() {
expect(column).to.eql({
column: 'NAME',
dataType: 'VARCHAR',
dataLength: 32
dataLength: 32,
});
});
@ -87,125 +87,125 @@ 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']
params: ['John'],
});
});
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: []
params: [],
});
});
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']
params: ['John', 'Mary'],
});
});
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']
params: ['John', 'Mary'],
});
});
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]
params: ['John', true],
});
});
it('builds where with a regexp string that does not have flags', function() {
var where = connector.buildWhere('customer', {
name: {
regexp: '^J'
}
regexp: '^J',
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: ['^J']
params: ['^J'],
});
});
it('builds where with a regexp string that has flags', function() {
var where = connector.buildWhere('customer', {
name: {
regexp: '^J/i'
}
regexp: '^J/i',
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: ['^J/i']
params: ['^J/i'],
});
});
it('builds where with a regexp literal that does not have flags', function() {
var where = connector.buildWhere('customer', {
name: {
regexp: /^J/
}
regexp: /^J/,
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: [/^J/]
params: [/^J/],
});
});
it('builds where with a regexp literal that has flags', function() {
var where = connector.buildWhere('customer', {
name: {
regexp: /^J/i
}
regexp: /^J/i,
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: [/^J/i]
params: [/^J/i],
});
});
it('builds where with a regexp object that does not have flags', function() {
var where = connector.buildWhere('customer', {
name: {
regexp: new RegExp(/^J/)
}
regexp: new RegExp(/^J/),
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: [/^J/]
params: [/^J/],
});
});
it('builds where with a regexp object that has flags', function() {
var where = connector.buildWhere('customer', {
name: {
regexp: new RegExp(/^J/i)
}
regexp: new RegExp(/^J/i),
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: [new RegExp(/^J/i)]
params: [new RegExp(/^J/i)],
});
});
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]
params: ['John', true],
});
});
@ -226,29 +226,29 @@ 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]
params: [true],
});
});
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]
params: ['John', true],
});
});
@ -258,71 +258,71 @@ 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']
params: ['John'],
});
});
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']
params: [false, 'John'],
});
});
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',
params: ['John']
params: ['John'],
});
});
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]
params: ['John', true],
});
});
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() {
@ -333,25 +333,25 @@ describe('sql connector', function() {
});
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');
});
@ -367,7 +367,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() {

View File

@ -13,18 +13,18 @@ describe('transactions', function() {
before(function(done) {
db = new juggler.DataSource({
connector: testConnector,
debug: true
debug: true,
});
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();
});
});
@ -36,9 +36,9 @@ describe('transactions', function() {
return function(done) {
// Transaction.begin(db.connector, Transaction.READ_COMMITTED,
Post.beginTransaction({
isolationLevel: Transaction.READ_COMMITTED,
timeout: timeout
},
isolationLevel: Transaction.READ_COMMITTED,
timeout: timeout,
},
function(err, tx) {
if (err) return done(err);
expect(typeof tx.id).to.eql('string');
@ -60,15 +60,15 @@ 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);
} else {
p.reviews.create({
author: 'John',
content: 'Review for ' + p.title
}, {transaction: tx, model: 'Review'},
author: 'John',
content: 'Review for ' + p.title,
}, { transaction: tx, model: 'Review' },
function(err, c) {
done(err);
});
@ -82,11 +82,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 +109,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));
@ -141,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));
@ -173,12 +173,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);