Skip to content

Commit

Permalink
Replace Lodash assign with Object.assign (#3343)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Jul 10, 2019
1 parent c6481e8 commit 416fb4d
Show file tree
Hide file tree
Showing 30 changed files with 84 additions and 91 deletions.
14 changes: 9 additions & 5 deletions src/client.js
Expand Up @@ -21,7 +21,7 @@ const inherits = require('inherits');
const { EventEmitter } = require('events');

const { makeEscape } = require('./query/string');
const { assign, uniqueId, cloneDeep, defaults } = require('lodash');
const { uniqueId, cloneDeep, defaults } = require('lodash');

const Logger = require('./logger');

Expand Down Expand Up @@ -69,7 +69,7 @@ function Client(config = {}) {

inherits(Client, EventEmitter);

assign(Client.prototype, {
Object.assign(Client.prototype, {
formatter(builder) {
return new Formatter(this, builder);
},
Expand Down Expand Up @@ -149,7 +149,7 @@ assign(Client.prototype, {

const { __knexUid, __knexTxId } = connection;

this.emit('query', assign({ __knexUid, __knexTxId }, obj));
this.emit('query', Object.assign({ __knexUid, __knexTxId }, obj));
debugQuery(obj.sql, __knexTxId);
debugBindings(obj.bindings, __knexTxId);

Expand All @@ -158,7 +158,11 @@ assign(Client.prototype, {
return this._query(connection, obj).catch((err) => {
err.message =
this._formatQuery(obj.sql, obj.bindings) + ' - ' + err.message;
this.emit('query-error', err, assign({ __knexUid, __knexTxId }, obj));
this.emit(
'query-error',
err,
Object.assign({ __knexUid, __knexTxId }, obj)
);
throw err;
});
},
Expand All @@ -169,7 +173,7 @@ assign(Client.prototype, {

const { __knexUid, __knexTxId } = connection;

this.emit('query', assign({ __knexUid, __knexTxId }, obj));
this.emit('query', Object.assign({ __knexUid, __knexTxId }, obj));
debugQuery(obj.sql, __knexTxId);
debugBindings(obj.bindings, __knexTxId);

Expand Down
8 changes: 3 additions & 5 deletions src/dialects/mssql/index.js
@@ -1,6 +1,6 @@
// MSSQL Client
// -------
const { assign, map, flatten, values } = require('lodash');
const { map, flatten, values } = require('lodash');
const inherits = require('inherits');

const Client = require('../../client');
Expand All @@ -13,8 +13,6 @@ const SchemaCompiler = require('./schema/compiler');
const TableCompiler = require('./schema/tablecompiler');
const ColumnCompiler = require('./schema/columncompiler');

const { isArray } = Array;

const SQL_INT4 = { MIN: -2147483648, MAX: 2147483647 };
const SQL_BIGINT_SAFE = { MIN: -9007199254740991, MAX: 9007199254740991 };

Expand All @@ -40,7 +38,7 @@ function Client_MSSQL(config = {}) {

inherits(Client_MSSQL, Client);

assign(Client_MSSQL.prototype, {
Object.assign(Client_MSSQL.prototype, {
dialect: 'mssql',

driverName: 'mssql',
Expand Down Expand Up @@ -350,7 +348,7 @@ assign(Client_MSSQL.prototype, {
}

if (
(isArray(obj.returning) && obj.returning.length > 1) ||
(Array.isArray(obj.returning) && obj.returning.length > 1) ||
obj.returning[0] === '*'
) {
return response;
Expand Down
4 changes: 2 additions & 2 deletions src/dialects/mssql/query/compiler.js
Expand Up @@ -3,7 +3,7 @@
const inherits = require('inherits');
const QueryCompiler = require('../../../query/compiler');

const { assign, isEmpty, compact, identity } = require('lodash');
const { isEmpty, compact, identity } = require('lodash');

function QueryCompiler_MSSQL(client, builder) {
QueryCompiler.call(this, client, builder);
Expand All @@ -23,7 +23,7 @@ const components = [
'offset',
];

assign(QueryCompiler_MSSQL.prototype, {
Object.assign(QueryCompiler_MSSQL.prototype, {
_emptyInsertValue: 'default values',

select() {
Expand Down
4 changes: 1 addition & 3 deletions src/dialects/mssql/schema/columncompiler.js
Expand Up @@ -3,8 +3,6 @@
const inherits = require('inherits');
const ColumnCompiler = require('../../../schema/columncompiler');

const { assign } = require('lodash');

function ColumnCompiler_MSSQL() {
ColumnCompiler.apply(this, arguments);
this.modifiers = ['nullable', 'defaultTo', 'first', 'after', 'comment'];
Expand All @@ -14,7 +12,7 @@ inherits(ColumnCompiler_MSSQL, ColumnCompiler);
// Types
// ------

assign(ColumnCompiler_MSSQL.prototype, {
Object.assign(ColumnCompiler_MSSQL.prototype, {
increments: 'int identity(1,1) not null primary key',

bigincrements: 'bigint identity(1,1) not null primary key',
Expand Down
4 changes: 1 addition & 3 deletions src/dialects/mssql/schema/compiler.js
Expand Up @@ -3,14 +3,12 @@
const inherits = require('inherits');
const SchemaCompiler = require('../../../schema/compiler');

const { assign } = require('lodash');

function SchemaCompiler_MSSQL(client, builder) {
SchemaCompiler.call(this, client, builder);
}
inherits(SchemaCompiler_MSSQL, SchemaCompiler);

assign(SchemaCompiler_MSSQL.prototype, {
Object.assign(SchemaCompiler_MSSQL.prototype, {
dropTablePrefix: 'DROP TABLE ',
dropTableIfExists(tableName) {
const name = this.formatter.wrap(prefixedTableName(this.schema, tableName));
Expand Down
4 changes: 1 addition & 3 deletions src/dialects/mssql/schema/tablecompiler.js
Expand Up @@ -6,8 +6,6 @@ const inherits = require('inherits');
const TableCompiler = require('../../../schema/tablecompiler');
const helpers = require('../../../helpers');

const { assign } = require('lodash');

// Table Compiler
// ------

Expand All @@ -16,7 +14,7 @@ function TableCompiler_MSSQL() {
}
inherits(TableCompiler_MSSQL, TableCompiler);

assign(TableCompiler_MSSQL.prototype, {
Object.assign(TableCompiler_MSSQL.prototype, {
createAlterTableMethods: ['foreign', 'primary'],
createQuery(columns, ifNot) {
const createStatement = ifNot
Expand Down
13 changes: 7 additions & 6 deletions src/dialects/mysql/index.js
@@ -1,7 +1,7 @@
// MySQL Client
// -------
const inherits = require('inherits');

const { map } = require('lodash');
const Client = require('../../client');
const Bluebird = require('bluebird');

Expand All @@ -11,7 +11,6 @@ const SchemaCompiler = require('./schema/compiler');
const TableCompiler = require('./schema/tablecompiler');
const ColumnCompiler = require('./schema/columncompiler');

const { assign, map } = require('lodash');
const { makeEscape } = require('../../query/string');

// Always initialize with the "QueryBuilder" and "QueryCompiler"
Expand All @@ -23,7 +22,7 @@ function Client_MySQL(config) {

inherits(Client_MySQL, Client);

assign(Client_MySQL.prototype, {
Object.assign(Client_MySQL.prototype, {
dialect: 'mysql',

driverName: 'mysql',
Expand Down Expand Up @@ -101,7 +100,7 @@ assign(Client_MySQL.prototype, {
// and pass that through to the stream we've sent back to the client.
_stream(connection, obj, stream, options) {
options = options || {};
const queryOptions = assign({ sql: obj.sql }, obj.options);
const queryOptions = Object.assign({ sql: obj.sql }, obj.options);
return new Bluebird((resolver, rejecter) => {
stream.on('error', rejecter);
stream.on('end', resolver);
Expand All @@ -127,7 +126,7 @@ assign(Client_MySQL.prototype, {
resolver();
return;
}
const queryOptions = assign({ sql: obj.sql }, obj.options);
const queryOptions = Object.assign({ sql: obj.sql }, obj.options);
connection.query(queryOptions, obj.bindings, function(err, rows, fields) {
if (err) return rejecter(err);
obj.response = [rows, fields];
Expand All @@ -148,7 +147,9 @@ assign(Client_MySQL.prototype, {
case 'select':
case 'pluck':
case 'first': {
if (method === 'pluck') return map(rows, obj.pluck);
if (method === 'pluck') {
return map(rows, obj.pluck);
}
return method === 'first' ? rows[0] : rows;
}
case 'insert':
Expand Down
4 changes: 2 additions & 2 deletions src/dialects/mysql/query/compiler.js
Expand Up @@ -3,7 +3,7 @@
const inherits = require('inherits');
const QueryCompiler = require('../../../query/compiler');

const { assign, identity } = require('lodash');
const { identity } = require('lodash');

function QueryCompiler_MySQL(client, builder) {
QueryCompiler.call(this, client, builder);
Expand All @@ -19,7 +19,7 @@ function QueryCompiler_MySQL(client, builder) {

inherits(QueryCompiler_MySQL, QueryCompiler);

assign(QueryCompiler_MySQL.prototype, {
Object.assign(QueryCompiler_MySQL.prototype, {
_emptyInsertValue: '() values ()',

// Update method, including joins, wheres, order & limits.
Expand Down
4 changes: 2 additions & 2 deletions src/dialects/mysql/schema/compiler.js
Expand Up @@ -3,14 +3,14 @@
const inherits = require('inherits');
const SchemaCompiler = require('../../../schema/compiler');

const { assign, some } = require('lodash');
const { some } = require('lodash');

function SchemaCompiler_MySQL(client, builder) {
SchemaCompiler.call(this, client, builder);
}
inherits(SchemaCompiler_MySQL, SchemaCompiler);

assign(SchemaCompiler_MySQL.prototype, {
Object.assign(SchemaCompiler_MySQL.prototype, {
// Rename a table on the schema.
renameTable(tableName, to) {
this.pushQuery(
Expand Down
4 changes: 1 addition & 3 deletions src/dialects/mysql/schema/tablecompiler.js
Expand Up @@ -5,8 +5,6 @@
const inherits = require('inherits');
const TableCompiler = require('../../../schema/tablecompiler');

const { assign } = require('lodash');

// Table Compiler
// ------

Expand All @@ -16,7 +14,7 @@ function TableCompiler_MySQL() {

inherits(TableCompiler_MySQL, TableCompiler);

assign(TableCompiler_MySQL.prototype, {
Object.assign(TableCompiler_MySQL.prototype, {
createQuery(columns, ifNot) {
const createStatement = ifNot
? 'create table if not exists '
Expand Down
4 changes: 2 additions & 2 deletions src/dialects/mysql/transaction.js
@@ -1,12 +1,12 @@
const Transaction = require('../../transaction');
const Debug = require('debug');
const { assign, isUndefined } = require('lodash');
const { isUndefined } = require('lodash');

const debug = Debug('knex:tx');

class Transaction_MySQL extends Transaction {}

assign(Transaction_MySQL.prototype, {
Object.assign(Transaction_MySQL.prototype, {
query(conn, sql, status, value) {
const t = this;
const q = this.trxClient
Expand Down
3 changes: 1 addition & 2 deletions src/dialects/mysql2/index.js
Expand Up @@ -2,7 +2,6 @@
// -------
const inherits = require('inherits');
const Client_MySQL = require('../mysql');
const { assign } = require('lodash');
const Transaction = require('./transaction');

// Always initialize with the "QueryBuilder" and "QueryCompiler"
Expand All @@ -13,7 +12,7 @@ function Client_MySQL2(config) {
}
inherits(Client_MySQL2, Client_MySQL);

assign(Client_MySQL2.prototype, {
Object.assign(Client_MySQL2.prototype, {
// The "dialect", for reference elsewhere.
driverName: 'mysql2',

Expand Down
4 changes: 2 additions & 2 deletions src/dialects/mysql2/transaction.js
@@ -1,11 +1,11 @@
const Transaction = require('../../transaction');
const debug = require('debug')('knex:tx');

const { assign, isUndefined } = require('lodash');
const { isUndefined } = require('lodash');

class Transaction_MySQL2 extends Transaction {}

assign(Transaction_MySQL2.prototype, {
Object.assign(Transaction_MySQL2.prototype, {
query(conn, sql, status, value) {
const t = this;
const q = this.trxClient
Expand Down
4 changes: 2 additions & 2 deletions src/dialects/oracle/index.js
@@ -1,6 +1,6 @@
// Oracle Client
// -------
const { assign, map, flatten, values } = require('lodash');
const { map, flatten, values } = require('lodash');

const inherits = require('inherits');
const Client = require('../../client');
Expand All @@ -25,7 +25,7 @@ function Client_Oracle(config) {

inherits(Client_Oracle, Client);

assign(Client_Oracle.prototype, {
Object.assign(Client_Oracle.prototype, {
dialect: 'oracle',

driverName: 'oracle',
Expand Down
4 changes: 2 additions & 2 deletions src/dialects/oracle/schema/columncompiler.js
@@ -1,4 +1,4 @@
const { assign, uniq, map } = require('lodash');
const { uniq, map } = require('lodash');
const inherits = require('inherits');
const Raw = require('../../../raw');
const ColumnCompiler = require('../../../schema/columncompiler');
Expand All @@ -13,7 +13,7 @@ function ColumnCompiler_Oracle() {
}
inherits(ColumnCompiler_Oracle, ColumnCompiler);

assign(ColumnCompiler_Oracle.prototype, {
Object.assign(ColumnCompiler_Oracle.prototype, {
// helper function for pushAdditional in increments() and bigincrements()
_createAutoIncrementTriggerAndSequence() {
// TODO Add warning that sequence etc is created
Expand Down
4 changes: 2 additions & 2 deletions src/dialects/oracle/schema/tablecompiler.js
Expand Up @@ -6,7 +6,7 @@ const TableCompiler = require('../../../schema/tablecompiler');
const helpers = require('../../../helpers');
const Trigger = require('./trigger');

const { assign, map } = require('lodash');
const { map } = require('lodash');

// Table Compiler
// ------
Expand All @@ -16,7 +16,7 @@ function TableCompiler_Oracle() {
}
inherits(TableCompiler_Oracle, TableCompiler);

assign(TableCompiler_Oracle.prototype, {
Object.assign(TableCompiler_Oracle.prototype, {
addColumns(columns, prefix) {
if (columns.sql.length > 0) {
prefix = prefix || this.addColumnsPrefix;
Expand Down
4 changes: 2 additions & 2 deletions src/dialects/oracledb/schema/columncompiler.js
@@ -1,15 +1,15 @@
const inherits = require('inherits');
const ColumnCompiler_Oracle = require('../../oracle/schema/columncompiler');

const { assign, isObject } = require('lodash');
const { isObject } = require('lodash');

function ColumnCompiler_Oracledb() {
ColumnCompiler_Oracle.apply(this, arguments);
}

inherits(ColumnCompiler_Oracledb, ColumnCompiler_Oracle);

assign(ColumnCompiler_Oracledb.prototype, {
Object.assign(ColumnCompiler_Oracledb.prototype, {
time: 'timestamp with local time zone',

datetime: function(withoutTz) {
Expand Down

0 comments on commit 416fb4d

Please sign in to comment.