2

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

2
  • what is the NAME field of the table? if you type .schema <table> you will get the definition. Also which sql library are you using with node? Commented Aug 31, 2022 at 3:08
  • the NAME field = 'name' varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL Commented Aug 31, 2022 at 3:20

1 Answer 1

1

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 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.