Skip to content
Advertisement

sqlite3 – insert – javascript object as values

What is the easiest solution to use a javascript object as values for a sqlite3 insert? The following code does not work.

JavaScript

Advertisement

Answer

First of all you need to write the SQL correctly. To insert into the columns name, age, language, you need to write the SQL like this:

JavaScript

And pass the values of the 3 columns as parameters.

JavaScript

Or if the property names in the JavaScript object correspond directly to the column names, then you can generate the correct SQL string dynamically to have more flexibility:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement