From ae1622c7e7df7dfeb05594058f555840bfcde8fe Mon Sep 17 00:00:00 2001 From: Mike Eldridge Date: Tue, 14 Jan 2020 19:45:48 -0600 Subject: [PATCH 1/2] only supply the id attribute to knex.insert for drivers that support it Knex 0.16.4 began warning when the returning attribute is supplied for dialects that do not support it. These dialects currently include MySQL and SQLite3. Supplying this attribute is a no-op for those dialects, so excluding them is safe and eliminates the warning. More information: https://github.com/knex/knex/pull/3039 --- src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 2d21b16..61641d0 100644 --- a/src/index.js +++ b/src/index.js @@ -421,6 +421,13 @@ function loadWithRelations (items, resourceConfig, options) { Adapter.extend({ constructor: SqlAdapter, + _returning (idAttribute) { + // Some knex client drivers do not support .returning(), so set the + // attribute to null to prevent knex from emitting warnings. + + return ['mysql', 'sqlite3'].includes(this.knexOpts.client) ? null : idAttribute + }, + _count (mapper, query, opts) { opts || (opts = {}) query || (query = {}) @@ -438,7 +445,7 @@ Adapter.extend({ const sqlBuilder = utils.isUndefined(opts.transaction) ? this.knex : opts.transaction return sqlBuilder(getTable(mapper)) - .insert(props, idAttribute) + .insert(props, this._returning(idAttribute)) .then((ids) => { const id = utils.isUndefined(props[idAttribute]) ? (ids.length ? ids[0] : undefined) : props[idAttribute] if (utils.isUndefined(id)) { From cc5440f1216bc8bb488b587f0a2538d4f3111788 Mon Sep 17 00:00:00 2001 From: Mike Eldridge Date: Tue, 14 Jan 2020 19:46:57 -0600 Subject: [PATCH 2/2] allow supplying a database password for tests and migrations Also make test/knexfile.js match mocha.start.js in terms of defaults for environment variables. --- mocha.start.js | 4 ++++ test/knexfile.js | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mocha.start.js b/mocha.start.js index 5b39dad..d41cb84 100644 --- a/mocha.start.js +++ b/mocha.start.js @@ -25,6 +25,10 @@ if (DB_CLIENT === 'sqlite3') { user: process.env.DB_USER || 'root', database: process.env.DB_NAME || 'test' } + + if (process.env.DB_PASS) { + connection.password = process.env.DB_PASS + } } JSDataAdapterTests.init({ diff --git a/test/knexfile.js b/test/knexfile.js index 3e7cf4a..22f5d75 100644 --- a/test/knexfile.js +++ b/test/knexfile.js @@ -9,8 +9,12 @@ if (DB_CLIENT === 'sqlite3') { } else { connection = { host: process.env.DB_HOST || '127.0.0.1', - user: process.env.DB_USER, - database: process.env.DB_NAME + user: process.env.DB_USER || 'root', + database: process.env.DB_NAME || 'test' + } + + if (process.env.DB_PASS) { + connection.password = process.env.DB_PASS } }