MyNameisLuke
MyNameisLuke

Reputation: 23

Trying to INSERT data into SQLite but getting empty response

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

Upvotes: 2

Views: 223

Answers (1)

Fabien Brocklesby
Fabien Brocklesby

Reputation: 91

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 });

Upvotes: 1

Related Questions