Hi all,I'm trying to use transactions in this scenario.1 - I create a transaction and cache its value:var cachedTransaction;
persistence.transaction(function (err, tx) {
if (!err) {
cachedTransaction = tx;
}
});
2 - I use this cached transaction in subsequent DB operations like so:var logAllUsers = function () {
User.all().list(cachedTransaction, function(err, users) {
users.forEach(function(user) {
console.log(user.name);
});
});
};
var logOneUser = function () {
User.all().one(cachedTransaction, function(err, user) {
console.log(user.name);
});
};....etcbut this gives me the following error:
- Uncaught Error: InvalidStateError: DOM Exception 11 persistence.store.websql.js:81
Is is possible to cache a transaction in this way and use it in multiple queries??ThanksManners.--
You received this message because you are subscribed to the Google Groups "persistence.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to persistencej...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hi all,I'm stil carrying out some test with transactions. I've moved away from caching the transaction and I'm now passing the transaction object to various functions that will later be executed as part of one "operation".I've created a jsfiddle to demonstrate this: http://jsfiddle.net/gotomanners/y7UBV/4/So continuing on from my example above, I pass the tx as an argument to `logAllUsers` and `logOneUser` and it runs fine as Mark said, multiple queries, one transaction.See Operation 1 in jsFiddle:
persistence.transaction(function (err, tx) {if (!err) {
logOneUser(tx); // onelogAllUsers(tx); // all}});but when I do the same as above but add a timeout between queries `logOneUser` and `logAllUsers` (simulating an ajax call or something) I get the same error as above.(See console)See Operation 2 in jsFiddle:
persistence.transaction(function (err, tx) {if (!err) {
logOneUser(tx); // onewindow.setTimeout(function() { // wait 400ms or any mslogAllUsers(tx); // all}, 400);}});
- Uncaught Error: InvalidStateError: DOM Exception 11 persistence.store.websql.js:81
Does anyone understand what is going on here?I thought maybe the tx object was lost due to different scope but that is not the case.