Dexie.transaction()-(old-version)
Syntax
db.transaction(mode, table, [table2], [tableN], ..., callback)Parameters
mode : String
"r" = readonly or "rw" = readwrite
Callback Parameters
Return Value
Sample
var db = new Dexie("FriendsAndPetsDatabase");
db.version(1).stores({
friends: "++id,name,isCloseFriend",
pets: "++id,name,kind"
});
db.open();
db.transaction("rw", db.friends, db.pets, function(friends, pets, transaction) {
// Since mode is "rw", we can add objects to the object stores
friends.add({name: "Måns", isCloseFriend: 1});
friends.add({name: "Nils", isCloseFriend: 1});
friends.add({name: "Jon", isCloseFriend: 1});
pets.add({name: "Josephina", kind: "dog"});
// In case you need to access the transaction object, here's an example of that:
transaction.on("abort", function() {
console.log("Transaction aborted");
});
// Since we are in a transaction, we can query the table right away.
// If this was not in a transaction, we would have to wait for
// all three add() operations
// to complete before querying it if we would like to get the latest added data.
friends.where("isCloseFriend").equals(1).each(function(friend){
console.log("Found close friend: " + friend.name);
// Any database error event that occur will abort transaction and
// be sent to the catch() method below.
// The exact same rule if any exception is thrown what so ever.
});
}).catch(function (error) {
// Log or display the error
console.error(error.stack || error);
});