Socket
Socket
Sign inDemoInstall

knex

Package Overview
Dependencies
25
Maintainers
5
Versions
252
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 2.4.0

11

lib/client.js

@@ -216,7 +216,12 @@ const { Pool, TimeoutError } = require('tarn');

const DEFAULT_ACQUIRE_TIMEOUT = 60000;
const timeouts = [
this.config.acquireConnectionTimeout || 60000,
poolConfig.acquireTimeoutMillis,
this.config.acquireConnectionTimeout,
poolConfig.acquireTimeoutMillis
].filter((timeout) => timeout !== undefined);
if (!timeouts.length) {
timeouts.push(DEFAULT_ACQUIRE_TIMEOUT)
}
// acquire connection timeout can be set on config or config.pool

@@ -400,3 +405,3 @@ // choose the smallest, positive timeout setting and set on poolConfig

// json columns can have object in values.
if (isPlainObject(value)) {
if (isPlainObject(value) || Array.isArray(value)) {
value = JSON.stringify(value);

@@ -403,0 +408,0 @@ }

@@ -283,3 +283,3 @@ /* eslint max-len:0 */

* @param {string | string[]} columns
* @param {string | {indexName: undefined | string, deferrable?: 'not deferrable'|'deferred'|'immediate', useConstraint?: true|false }} indexName
* @param {string | {indexName: undefined | string, deferrable?: 'not deferrable'|'deferred'|'immediate', useConstraint?: true|false, predicate?: QueryBuilder }} indexName
*/

@@ -290,4 +290,5 @@ unique(columns, indexName) {

let useConstraint = false;
let predicate;
if (isObject(indexName)) {
({ indexName, deferrable, useConstraint } = indexName);
({ indexName, deferrable, useConstraint, predicate } = indexName);
}

@@ -299,2 +300,5 @@ if (deferrable && deferrable !== 'not deferrable') {

}
if (useConstraint && predicate) {
throw new Error('mssql cannot create constraint with predicate');
}
indexName = indexName

@@ -308,6 +312,2 @@ ? this.formatter.wrap(indexName)

const whereAllTheColumnsAreNotNull = columns
.map((column) => this.formatter.columnize(column) + ' IS NOT NULL')
.join(' AND ');
if (useConstraint) {

@@ -322,8 +322,14 @@ // mssql supports unique indexes and unique constraints.

} else {
// make unique constraint that allows null https://stackoverflow.com/a/767702/360060
// default to making unique index that allows null https://stackoverflow.com/a/767702/360060
// to be more or less compatible with other DBs (if any of the columns is NULL then "duplicates" are allowed)
const predicateQuery = predicate
? ' ' + this.client.queryCompiler(predicate).where()
: ' WHERE ' +
columns
.map((column) => this.formatter.columnize(column) + ' IS NOT NULL')
.join(' AND ');
this.pushQuery(
`CREATE UNIQUE INDEX ${indexName} ON ${this.tableName()} (${this.formatter.columnize(
columns
)}) WHERE ${whereAllTheColumnsAreNotNull}`
)})${predicateQuery}`
);

@@ -330,0 +336,0 @@ }

// MySQL Query Compiler
// ------
const assert = require('assert');
const identity = require('lodash/identity');
const isPlainObject = require('lodash/isPlainObject');
const isEmpty = require('lodash/isEmpty');
const QueryCompiler = require('../../../query/querycompiler');

@@ -11,2 +14,5 @@ const { wrapAsIdentifier } = require('../../../formatter/formatterUtils');

const isPlainObjectOrArray = (value) =>
isPlainObject(value) || Array.isArray(value);
class QueryCompiler_MySQL extends QueryCompiler {

@@ -135,3 +141,4 @@ constructor(client, builder, formatter) {

columns[val.COLUMN_NAME] = {
defaultValue: val.COLUMN_DEFAULT === 'NULL' ? null : val.COLUMN_DEFAULT,
defaultValue:
val.COLUMN_DEFAULT === 'NULL' ? null : val.COLUMN_DEFAULT,
type: val.DATA_TYPE,

@@ -161,2 +168,21 @@ maxLength: val.CHARACTER_MAXIMUM_LENGTH,

whereBasic(statement) {
assert(
!isPlainObjectOrArray(statement.value),
'The values in where clause must not be object or array.'
);
return super.whereBasic(statement);
}
whereRaw(statement) {
assert(
isEmpty(statement.value.bindings) ||
!Object.values(statement.value.bindings).some(isPlainObjectOrArray),
'The values in where clause must not be object or array.'
);
return super.whereRaw(statement);
}
whereLike(statement) {

@@ -163,0 +189,0 @@ return `${this._columnClause(statement)} ${this._not(

@@ -192,5 +192,16 @@ /* eslint max-len: 0 */

let deferrable;
let useConstraint = true;
let predicate;
if (isObject(indexName)) {
({ indexName, deferrable } = indexName);
({ indexName, deferrable, useConstraint, predicate } = indexName);
if (useConstraint === undefined) {
useConstraint = !!deferrable || !predicate;
}
}
if (!useConstraint && deferrable && deferrable !== 'not deferrable') {
throw new Error('postgres cannot create deferrable index');
}
if (useConstraint && predicate) {
throw new Error('postgres cannot create constraint with predicate');
}
deferrable = deferrable ? ` deferrable initially ${deferrable}` : '';

@@ -200,9 +211,22 @@ indexName = indexName

: this._indexCommand('unique', this.tableNameRaw, columns);
this.pushQuery(
`alter table ${this.tableName()} add constraint ${indexName}` +
' unique (' +
this.formatter.columnize(columns) +
')' +
deferrable
);
if (useConstraint) {
this.pushQuery(
`alter table ${this.tableName()} add constraint ${indexName}` +
' unique (' +
this.formatter.columnize(columns) +
')' +
deferrable
);
} else {
const predicateQuery = predicate
? ' ' + this.client.queryCompiler(predicate).where()
: '';
this.pushQuery(
`create unique index ${indexName} on ${this.tableName()} (${this.formatter.columnize(
columns
)})${predicateQuery}`
);
}
}

@@ -209,0 +233,0 @@

@@ -54,3 +54,3 @@ const filter = require('lodash/filter');

const defaultTo = col.modified['defaultTo']
? formatDefault(col.modified['defaultTo'][0], type, this.client)
? formatDefault(col.modified['defaultTo'][0], col.type, this.client)
: null;

@@ -136,4 +136,5 @@

let deferrable;
let predicate;
if (isObject(indexName)) {
({ indexName, deferrable } = indexName);
({ indexName, deferrable, predicate } = indexName);
}

@@ -149,4 +150,9 @@ if (deferrable && deferrable !== 'not deferrable') {

columns = this.formatter.columnize(columns);
const predicateQuery = predicate
? ' ' + this.client.queryCompiler(predicate).where()
: '';
this.pushQuery(
`create unique index ${indexName} on ${this.tableName()} (${columns})`
`create unique index ${indexName} on ${this.tableName()} (${columns})${predicateQuery}`
);

@@ -153,0 +159,0 @@ }

@@ -38,6 +38,10 @@ const _debugQuery = require('debug')('knex:query');

return client._query(connection, queryObject).catch((err) => {
err.message =
formatQuery(queryObject.sql, queryObject.bindings, undefined, client) +
' - ' +
err.message;
if (client.config && client.config.compileSqlOnError === false) {
err.message = queryObject.sql + ' - ' + err.message;
} else {
err.message =
formatQuery(queryObject.sql, queryObject.bindings, undefined, client) +
' - ' +
err.message;
}
client.emit(

@@ -44,0 +48,0 @@ 'query-error',

@@ -530,2 +530,3 @@ // Builder

const raw = sql.isRawInstance ? sql : this.client.raw(sql, bindings);
this._statements.push({

@@ -1505,13 +1506,12 @@ grouping: 'where',

orWhereJsonObject(column, operator, value) {
return this._bool('or').whereJsonObject(column, operator, value);
orWhereJsonObject(column, value) {
return this._bool('or').whereJsonObject(column, value);
}
whereNotJsonObject(column, value) {
this._not(true)._whereJsonWrappedValue('whereJsonObject', column, value);
return this;
return this._not(true).whereJsonObject(column, value);
}
orWhereNotJsonObject(column, operator, value) {
return this._not(true)._bool('or').whereJsonObject(column, operator, value);
orWhereNotJsonObject(column, value) {
return this._bool('or').whereNotJsonObject(column, value);
}

@@ -1535,14 +1535,11 @@

whereJsonNotSupersetOf(column, value) {
this._not(true).whereJsonSupersetOf(column, value);
return this;
return this._not(true).whereJsonSupersetOf(column, value);
}
orWhereJsonSupersetOf(column, value) {
this._whereJsonWrappedValue('whereJsonSupersetOf', column, value);
return this;
return this._bool('or').whereJsonSupersetOf(column, value);
}
orWhereJsonNotSupersetOf(column, value) {
this._not(true)._bool('or').whereJsonSupersetOf(column, value);
return this;
return this._bool('or').whereJsonNotSupersetOf(column, value);
}

@@ -1557,14 +1554,11 @@

whereJsonNotSubsetOf(column, value) {
this._not(true).whereJsonSubsetOf(column, value);
return this;
return this._not(true).whereJsonSubsetOf(column, value);
}
orWhereJsonSubsetOf(column, value) {
this._whereJsonWrappedValue('whereJsonSubsetOf', column, value);
return this;
return this._bool('or').whereJsonSubsetOf(column, value);
}
orWhereJsonNotSubsetOf(column, value) {
this._not(true)._bool('or').whereJsonSubsetOf(column, value);
return this;
return this._bool('or').whereJsonNotSubsetOf(column, value);
}

@@ -1571,0 +1565,0 @@

{
"name": "knex",
"version": "2.3.0",
"version": "2.4.0",
"description": "A batteries-included SQL query & schema builder for PostgresSQL, MySQL, CockroachDB, MSSQL and SQLite3",

@@ -135,3 +135,3 @@ "main": "knex",

"rimraf": "^3.0.2",
"sinon": "^14.0.0",
"sinon": "^15.0.1",
"sinon-chai": "^3.7.0",

@@ -145,4 +145,4 @@ "source-map-support": "^0.5.21",

"ts-node": "^10.9.1",
"tsd": "^0.23.0",
"typescript": "4.8.2"
"tsd": "^0.25.0",
"typescript": "4.8.3"
},

@@ -149,0 +149,0 @@ "buildDependencies": [

@@ -67,3 +67,4 @@ #!/usr/bin/env node

const relativeJsPath = relativeTsPath.slice(0, relativeTsPath.length - 3) + '.js'
return relativeJsPath
// Always use POSIX-style path separators - .gitignore requires it
return relativeJsPath.split(path.sep).join(path.posix.sep);
})

@@ -70,0 +71,0 @@ const jsFilesToIgnoreString = jsFilesToIgnore.join('\n')

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc