How to return the data registered in the database using Sqlite3

Asked

Viewed 67 times

0

Good evening guys, okay I’m new here, and I have the following problem, I’m using knexJS with Sqlite3, I was able to do the Insert and is registering the data normally in the database, but when I send the data by nodemon, it returns only the id, and not the registered data.

I searched and noticed that Sqlite3 returns the id by default, and I don’t know how to fix it.

Thank you for your attention.

inserir a descrição da imagem aqui

1 answer

1

When we’re talking about the Knex.js, it expects you to pass one returning as the second parameter in the method insert.

In that case you have two options:

knex.insert({title: 'Great Gatsby'}, ['*']).into('books')

Or

knex('books')
   .returning('*')
   .insert({title: 'Slaughterhouse Five'})

The default behavior of the Knex is not to bring this data in the Insert, so you have to either use the returning explicitly or the second parameter of insert which is a shortcut.

More information can be seen on documentation.

  • So Mark I appreciate your attention but the problem is that Sqlite3 does not support the returning(); understand?

  • Ah, got it. In SQL I hardly touched :/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.