-
Notifications
You must be signed in to change notification settings - Fork 31
Insert
Jayr Alencar edited this page Mar 30, 2016
·
3 revisions
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
sqlite.insert('COMPANYS',{NAME: "My Company"},function(id){
console.log(id) //last insert id
});
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']);
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)
});