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/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)) { 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 } }