Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mocha.start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand All @@ -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)) {
Expand Down
8 changes: 6 additions & 2 deletions test/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down