gpbaculio
gpbaculio

Reputation: 5968

how to return the inserted data from mysql with knexjs?

i am learning knexjs and this is my code:

await knex('vendor_message').insert(data).returning(['message_id',
          'type',
          'content',
          'created_on',
          'last_update_on',
          'vendor_email']);

i was expecting it to return those fields from the db something like this:

[ 
 {
  'message_id': 'asdsd',
  'type':2,
  'content':'adddd',
  'created_on':'xxxx',
  'last_update_on':'xxxx',
  'vendor_email':'[email protected]'
 }
]

but it only returns the id: e.g.:

[ 687 ]

i don't want to return the arguments inserted, i want it from the db

Upvotes: 3

Views: 3424

Answers (1)

felixmosh
felixmosh

Reputation: 35493

returning is not supported by MySQL.

Utilized by PostgreSQL, MSSQL, and Oracle databases, the returning method specifies which column should be returned by the insert and update methods.

Just use the insert id to fetch the new row.

Upvotes: 4

Related Questions