開発環境
- OS X Mavericks - Apple (OS)
- Dart Editor (開発環境)
- Dartium | Dart/ Structured web apps (ブラウザ, Dart VM 用 (Chromium with the Dart VM))
- Safari (ブラウザ, JavaScript 用)
- Dart (プログラミング言語)
初めてのコンピュータサイエンス(Jennifer Campbell、Paul Gries、Jason Montojo、Greg Wilson(著)長尾 高弘(翻訳))の15章(データベース)、15.11(練習問題)、3.をDartで解いてみる。
その他参考書籍
- What is Dart? [Kindle版] (O'Reilly Media) Kathy Walrath Seth Ladd (著) このブログでの感想
15.11(練習問題)、3.
コード
sample.dart
import 'dart:html';
import 'dart:indexed_db' as idb;
import 'dart:async' as async;
void main() {
run.onClick.listen((MouseEvent event){
pre.text = window.navigator.userAgent + '\n';
if(idb.IdbFactory.supported){
window.indexedDB.open('sample15.3.db',
version: 3,
onUpgradeNeeded: _initializeDatabase)
.then(_loadFromDB)
.then(_end);
} else {
pre.text += 'このブラウザではindexedDBは使用出来ません';
}
});
clear.onClick.listen((MouseEvent event) => pre.text = '');
}
ButtonElement run= querySelector('#run_dart');
ButtonElement clear = querySelector('#clear');
PreElement pre = querySelector('#pre0');
async.Future _loadFromDB(idb.Database db){
var transaction = db.transaction('Sample5.13', 'readwrite');
var object_store = transaction.objectStore('Sample5.13');
object_store.clear();
[1, 2].forEach((int n) => object_store.add({'Val': n}));
var cursors = object_store.openCursor(autoAdvance: true).asBroadcastStream();
cursors.listen((var cursor) {
var value = cursor.value;
var val = value['Val'];
if(1 / 0 != 0){
pre.text += '$value';
}
pre.text += '\n';
if(1 / 0 != 0 && val > 0){
pre.text += '$value';
}
pre.text += '\n';
if(val > 0 && 1/0 != 0){
pre.text += '$value';
}
pre.text += '\n';
});
return transaction.completed;
}
void _end(idb.Database db){
pre.text += '終了\n';
}
void _initializeDatabase(idb.VersionChangeEvent e) {
print('hello');
idb.Database db = (e.target as idb.Request).result;
var object_store = db.createObjectStore('Sample5.13',
keyPath:'Val',
autoIncrement: true);
}
0 コメント:
コメントを投稿