Closed TimDaub closed 1 year ago
They are different in that open()
is called as a direction function, whereas openDB()
is a method on the database returned from open()
. It is probably easiest to do:
root = open({path: './data'});
dbA = root.openDB('a');
dbB = root.openDB('b');
OK, but say I call open twice with the same path but different name and I then do
dbA.transaction(() => { dbA.put(…); dbB.put(…); });
Is there now a guarantee that values for dbA and dbB are written atomically? Or does that only work if I open the connection like you showed it and then call root.transaction(…)?
No, that would only work if they were opened from the same database. Note, that another way you could do this is:
dbA= open({name: "a", path: './data'});
dbB = root.openDB('b');
ok great thanks!
Hey,
for a while I have used
open({name: "a", path: "./data"})
and then in another module, I have conveniently usedopen({name: "b", path: "./data"})
. I've now recently run into an issue with atomicity because a storage operation of db_a and db_b rely on each other. So I read more on transactions and atomicity usingopenDB
(https://github.com/kriszyp/lmdb-js#dbopendbdatabase-stringnamestring) and it is exactly what I'd need. However, for now I've been using open with two different names but the same path. So will I have to convert one to the other or is "open" and "openDB" interchangeable in this case, as long as its called with the same path?