WebReflection / dblite

sqlite for node.js without gyp problems
MIT License
209 stars 34 forks source link

is there a way to know when sqlite has finished writing the db file? #9

Closed Felix-N closed 10 years ago

Felix-N commented 10 years ago

currently i've not seen a practical solution to know when writing the db file finished (successfully).

WebReflection commented 10 years ago

maybe this is duplicated ?

WebReflection commented 10 years ago

Anyway, version 0.3.3 should invoke the callback, if specified, no matter what kind of query it is ( technically even after a BEGIN TRANSACTION and no idea what would happen ^_^ )

Is this good enough? Cheers

Felix-N commented 10 years ago

thanks - though i actually meant a different step.

sqlite is writing the db file to the filesystem with a delay. we're creating sqlite files on the fly and would like to process them further (zip, copy etc.) as soon as they're done.

so far i've not seen an elegant way of knowing when the writing finishes, instead of checking either for the sqlite process or if the filesize stops changing.

WebReflection commented 10 years ago

that's actually straight forward through the close listener.

var db = dblite('filename');

// add the handler
db.on('close', function () {
  // you can be sure the file is written
  // and you can do operations on it
});

// do any operation you want
// and when you've done it ...
db.close();

That's pretty much it since the very beginning close ensure that .exit is performed once everything has been done before that call.

Otherwise you can use sqlite3 commands and write an .exit manually as SQL but you need an info listener in that case but close will be fired/notified regardless.

Does this solve?

Felix-N commented 10 years ago

cheers - actually solves it perfectly. i missed the on close completely :)