Skip to content

Commit ae1622c

Browse files
author
Mike Eldridge
committed
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: knex/knex#3039
1 parent 7a40af5 commit ae1622c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,13 @@ function loadWithRelations (items, resourceConfig, options) {
421421
Adapter.extend({
422422
constructor: SqlAdapter,
423423

424+
_returning (idAttribute) {
425+
// Some knex client drivers do not support .returning(), so set the
426+
// attribute to null to prevent knex from emitting warnings.
427+
428+
return ['mysql', 'sqlite3'].includes(this.knexOpts.client) ? null : idAttribute
429+
},
430+
424431
_count (mapper, query, opts) {
425432
opts || (opts = {})
426433
query || (query = {})
@@ -438,7 +445,7 @@ Adapter.extend({
438445

439446
const sqlBuilder = utils.isUndefined(opts.transaction) ? this.knex : opts.transaction
440447
return sqlBuilder(getTable(mapper))
441-
.insert(props, idAttribute)
448+
.insert(props, this._returning(idAttribute))
442449
.then((ids) => {
443450
const id = utils.isUndefined(props[idAttribute]) ? (ids.length ? ids[0] : undefined) : props[idAttribute]
444451
if (utils.isUndefined(id)) {

0 commit comments

Comments
 (0)