Home > Enterprise >  Trying to INSERT data into SQLite but getting empty response
Trying to INSERT data into SQLite but getting empty response

Time:08-31

I am able to query the DB and get info back but when I try to insert a row in an SQLite DB , I get an empty response.

My query that returns something:

const response = await sql('SELECT * FROM work_orders ORDER BY CASE WHEN status = "OPEN" THEN 1 WHEN status = "CLOSED" THEN 2 ELSE 3 END')

and the insertion that won't work:

const response = await sql('INSERT INTO work_orders (name, status) VALUES (?, "OPEN")', workOrderName);
return res.status(201).json({ response });

What could I be missing?

the table was created with id INTEGER PRIMARY KEY AUTOINCREMENT

CodePudding user response:

I dont really know SQLite but maybe if you try RETURNING *, it may work.

const response = await sql('INSERT INTO work_orders (name, status) VALUES (?, "OPEN") RETURNING *', workOrderName);
return res.status(201).json({ response });
  • Related