node-sqlite3 icon indicating copy to clipboard operation
node-sqlite3 copied to clipboard

Question about serialize

Open IgorNadj opened this issue 11 years ago • 1 comments

I want a create table query to run first, then the others can run in any order.

Is this the correct format?

db.serialize(function(){
  db.run('CREATE TABLE test;');
});
db.run('INSERT INTO test ...');
db.run('INSERT INTO test ...');

Thanks!

IgorNadj avatar Oct 26 '15 09:10 IgorNadj

Yes. Serializing the create query will run it exclusively and the other queries will wait for it to finish before starting.

Graham--M avatar Nov 05 '15 00:11 Graham--M