Skip to content
Jayr Alencar edited this page Mar 30, 2016 · 3 revisions

1 - Just entity and data (Synchronous )

The object keys must have the same names as the columns in the database table.

var id = sqlite.insert('COMPANYS',{NAME: "My Company"});
console.log(id)//Last insert id

2 - Just entity and data (Asynchronous )

sqlite.insert('COMPANYS',{NAME: "My Company"},function(id){
   console.log(id) //last insert id
});

3 - Synchronous - Common Sql

var sqlite = require('sqlite-sync');

sqlite.connect('myDatabase.db');

//returns the last id
var last_insert_id = sqlite.run("INSERT INTO myTable (name) VALUES ('Jayr')");

//Prepared SQL
var last_insert_id = sqlite.run("INSERT INTO myTable (name) VALUES (?)",['Jayr']);

4 - Asynchronous - Common Sql

sqlite.connect('myDatabase.db');

sqlite.run("INSERT INTO myTable (name) VALUES ('Jayr')", function(id){
   //returns the last id
   console.log(id);
});

//Prepared SQL
sqlite.run("INSERT INTO myTable (name) VALUES (?)",['Jayr'],function(id){
   //returns the last id
   console.log(id)
});