feathersjs-ecosystem/feathers-knex

Patch has broke for MSSQL adapter: selecting the same field twice returns an array

jerfowler opened this issue · 1 comments

Steps to reproduce

The mssql knex adapter returns an array if the same field name is used more than once. Changes made in #181 have caused this to become an issue.

The following code will error:

const result = await app.service('uuids').patch(uid, { location:'Chicago' });

This line creates a duplicate uid field in the select statement:

query: _.extend({}, params.query, { $select: [ this.id ] })

Because we always append the id here:

q = filters.$select ? q.select(...filters.$select.concat(`${table}.${id}`))

This is the debug info from knex showing the double field:

{ method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 'FB9FFCB8-946B-45A3-BDAD-7311EB12182B' ],
  __knexQueryUid: 'a55481f2-dc42-4389-ae81-49619a327e3a',
  sql:
   'select [uid], [uuids].[uid] from [uuids] where (([uid] = ?))' }

The mssql adapter returns an array for uid for some unkown reason:

[ { uid:
     [ 'C958C0E3-3ACF-44E4-ADB3-8E9386A749BA',
       'C958C0E3-3ACF-44E4-ADB3-8E9386A749BA' ] } ]

So array is then passed into the update statement which causes the syntax error because its double wrapped in parentheses:

GeneralError: update [users] set [location] = @p0 where [id] in ((@p1, @p2));select @@rowcount - Incorrect syntax near ','.

Expected behavior

Tell us what should happen

  • patches without error

Actual behavior

Tell us what happens instead

  • syntax error

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):
"@feathersjs/feathers": "^3.3.1",
"feathers-knex": "^5.0.3",
"knex": "^0.14.6",
"mssql": "^4.1.0",

NodeJS version:
10.15.0

daffl commented

Closed via #189