You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add 'sqlite3' to the @feathersjs/knex/src/adapter.ts:27's RETURNING_CLIENTS const list, in order to return the correct id column from INSERT statements
I'm a new user of feathers, and recently created my first project, and chose sqlite as the database since I was just toying around
I tried to change the primary key on the user and other generated service's tables to use a uuid instead of the incremental integer, but no matter what I tried to change in the migrations and schemas, the create route was always throwing a 404 NotFound, even if the row was correctly inserted:
{
"name": "NotFound",
"message": "No record found for id '1'",
"code": 404,
"className": "not-found"
}
So my migration's up() was pretty much:
exportasyncfunctionup(knex: Knex): Promise<void>{awaitknex.schema.createTable('users',(table)=>{// changed from .increments() to .uuid() table.uuid('id').primary().defaultTo(knex.fn.uuid())// changed usernameField from "email" to "username" at the correct places in local auth strategy and schemastable.string('username').unique()table.string('password')})}
So I decided to look into the _create(data, params) method at the KnexAdapter at @feathersjs/knex , and I realized the issue was probably related to this:
// This probably tells knex to add a "RETURNING <primaryKeyColumn>"// clause (available at only a few db clients) at the end of the INSERT statementconstreturning=RETURNING_CLIENTS.includes(clientasstring) ? [this.id] : []constrows: any=awaitthis.db(params).insert(data,returning,{includeTriggerModifications: true}).catch(errorHandler)// This one seems to try and pick the primary key from results...constid=data[this.id]||rows[0][this.id]||rows[0]if(!id){returnrowsasResult[]}// ...to issue a SELECT statement and return the complete rowreturnthis._get(id,{
...params,query: _.pick(params?.query||{},'$select')})
It seems that sqlite3 returns this ROWID like [1] by default when inserting, which is then used as the primary key for the subsequent _get() call, probably causing the NotFound error I've mentioned.
Then I tried altering this line at adapter.js to include sqlite3 on the RETURNING_CLIENTS list:
Therefore, I'd like to suggest simply including sqlite to the list of clients that implement the RETURNING clause, to correctly return created items at insert calls
The text was updated successfully, but these errors were encountered:
I'm a new user of feathers, and recently created my first project, and chose
sqlite
as the database since I was just toying aroundI tried to change the primary key on the
user
and other generated service's tables to use auuid
instead of the incrementalinteger
, but no matter what I tried to change in the migrations and schemas, thecreate
route was always throwing a 404 NotFound, even if the row was correctly inserted:So my migration's
up()
was pretty much:So I decided to look into the
_create(data, params)
method at the KnexAdapter at@feathersjs/knex
, and I realized the issue was probably related to this:At @feathersjs/knex/src/adapter.ts, lines 243 to 256:
And at line 27:
So, the
sqlite
orsqlite3
is missing from this list.Then I looked into SQLite's official documentation and found out that:
INTEGER
for all tables, by defaultIt seems that
sqlite3
returns thisROWID
like[1]
by default when inserting, which is then used as the primary key for the subsequent_get()
call, probably causing the NotFound error I've mentioned.Then I tried altering this line at adapter.js to include
sqlite3
on the RETURNING_CLIENTS list:and voilà, got the expected response from calling the
create
method on the API:Therefore, I'd like to suggest simply including
sqlite
to the list of clients that implement the RETURNING clause, to correctly return created items at insert callsThe text was updated successfully, but these errors were encountered: