blob: 3d396ef698399b472137bde13247fb6db1ebcd43 [file] [log] [blame]
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of $LIBRARYNAME;
@DocsEditable()
$(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
@DomName('IDBDatabase.createObjectStore')
@DocsEditable()
ObjectStore createObjectStore(String name,
{String keyPath, bool autoIncrement}) {
var options = {};
if (keyPath != null) {
options['keyPath'] = keyPath;
}
if (autoIncrement != null) {
options['autoIncrement'] = autoIncrement;
}
return _createObjectStore(name, options);
}
$if DART2JS
Transaction transaction(storeName_OR_storeNames, String mode) {
if (mode != 'readonly' && mode != 'readwrite') {
throw new ArgumentError(mode);
}
// TODO(sra): Ensure storeName_OR_storeNames is a string or List<String>,
// and copy to JavaScript array if necessary.
// Try and create a transaction with a string mode. Browsers that expect a
// numeric mode tend to convert the string into a number. This fails
// silently, resulting in zero ('readonly').
return _transaction(storeName_OR_storeNames, mode);
}
Transaction transactionStore(String storeName, String mode) {
if (mode != 'readonly' && mode != 'readwrite') {
throw new ArgumentError(mode);
}
// Try and create a transaction with a string mode. Browsers that expect a
// numeric mode tend to convert the string into a number. This fails
// silently, resulting in zero ('readonly').
return _transaction(storeName, mode);
}
Transaction transactionList(List<String> storeNames, String mode) {
if (mode != 'readonly' && mode != 'readwrite') {
throw new ArgumentError(mode);
}
List storeNames_1 = convertDartToNative_StringArray(storeNames);
return _transaction(storeNames_1, mode);
}
Transaction transactionStores(DomStringList storeNames, String mode) {
if (mode != 'readonly' && mode != 'readwrite') {
throw new ArgumentError(mode);
}
return _transaction(storeNames, mode);
}
@JSName('transaction')
Transaction _transaction(stores, mode) native;
$else
Transaction transaction(storeName_OR_storeNames, String mode) {
if (mode != 'readonly' && mode != 'readwrite') {
throw new ArgumentError("Invalid transaction mode $mode");
}
var names;
if (storeName_OR_storeNames == null) {
throw new ArgumentError("stores may not be null in transaction");
} else if (storeName_OR_storeNames is String || storeName_OR_storeNames is DomStringList) {
names = storeName_OR_storeNames;
} else if (storeName_OR_storeNames is List<String>) {
names = convertDartToNative_List(storeName_OR_storeNames);
} else {
throw new ArgumentError("Invalid store(s) $store_Name_OR_storeNames");
}
return _blink.BlinkIDBDatabase.instance.transaction_Callback_2_(this, names, mode);
}
Transaction transactionList(List<String> storeNames, String mode) => transaction(storeNames, mode);
Transaction transactionStores(List<String> storeNames, String mode) => transaction(storeNames, mode);
Transaction transactionStore(String storeName, String mode) => transaction(storeName, mode);
$endif
$!MEMBERS}