transaction 

対象のオブジェクトストアへの複数の操作を1つのトランザクション内で行う。

シグネチャ 

deferred = gaviaStoreObject.transaction(store..., callback);

storeは複数指定可能。 callbackは引数の最後にしなければならない。

パラメータ 

名前 概要 デフォルト値
store
callback トランザクション内で行う処理。 callbackへは、transactionに渡したstore...と同じだけの数のtransactionStoreオブジェクトが引数として渡される。 falseを返すと、transaction全体がabortされる。

transactionStore 

callbackに渡されるオブジェクト。 storeに対して変更を行うメソッドが2つ用意されている。

  1. transactionStore.add(value) : オブジェクトストアにオブジェクトを追加する。
  2. transactionStore.remove(key) : オブジェクトストアからオブジェクトを削除する。

サンプル 

// store, other, anotherはいずれもGaviaのオブジェクトストアを意味する。
store.transaction(function(store) {
	store.add({
		id: 123
	});
	store.remove(234);
});

store.transaction(other, another, function(store, other, another) {
	store.add({
		id: 123
	});
	other.remove(234);
	another.add({
		id: 123
	});
});

store.tramsaction(other, function(other) {
	store.add({
		id: 123
	});
	other.remove(234);
	return false; // ここで書かれた処理全体が取り消される。
});