Lovefield: Google用純JS開發的跨瀏覽器,SQL似的關系查詢引擎
Lovefield是一個純JavaScript開發的關系查詢引擎。它還提供在瀏覽器端持久化數據的功能,比如使用IndexedDB在本地存儲數據。它還提供類似于SQL的語法。支持Chrome 37+, Firefox 31+, IE 10+, and Safari 5.1+等瀏覽器。
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Minimal example of using Lovefield</title>
<script src="lovefield.min.js"></script>
</head>
<body>
<script>
var schemaBuilder = lf.schema.create('todo', 1);
schemaBuilder.createTable('Item').
addColumn('id', lf.Type.INTEGER).
addColumn('description', lf.Type.STRING).
addColumn('deadline', lf.Type.DATE_TIME).
addColumn('done', lf.Type.BOOLEAN).
addPrimaryKey(['id']).
addIndex('idxDeadline', ['deadline'], false, lf.Order.DESC);
var todoDb;
var item;
schemaBuilder.connect().then(function(db) {
todoDb = db;
item = db.getSchema().table('Item');
var row = item.createRow({
'id': 1,
'description': 'Get a cup of coffee',
'deadline': new Date(),
'done': false
});
return db.insertOrReplace().into(item).values([row]).exec();
}).then(function() {
return todoDb.select().from(item).where(item.done.eq(false)).exec();
}).then(function(results) {
results.forEach(function(row) {
console.log(row['description'], 'before', row['deadline']);
});
});
</script>
</body>
</html> 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!