Last active
January 28, 2016 11:32
-
-
Save kenjitayama/130b4c09348a305f7c68 to your computer and use it in GitHub Desktop.
Sample for trying out Lovefield DB Inspector (SPAC version)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Sample for trying out Lovefield DB Inspector (SPAC version)</title> | |
<script type="text/javascript" src="https://rawgithub.com/kenjitayama/lovefield_spac_example/2aa2b1663edef3b57fafc7e782aadf74b12a7f4e/appdb.js"></script> | |
</head> | |
<body> | |
<script> | |
var todoDb; | |
var item; | |
var comment; | |
appdb.connect({enableInspector: true}).then(function(db) { | |
todoDb = db; | |
item = db.getSchema().getItem(); | |
comment = db.getSchema().getComment(); | |
var row = item.createRow({ | |
'id': 1, | |
'description': 'Get a cup of coffee', | |
'deadline': new Date(), | |
'done': false | |
}); | |
var commentRow = comment.createRow({ | |
'id': 1, | |
'itemId': 1, | |
'text': 'OK!' | |
}); | |
return db.insertOrReplace().into(item).values([row]).exec(). | |
then(function() { | |
return db.insertOrReplace().into(comment).values([commentRow]).exec(); | |
}); | |
}).then(function() { | |
return todoDb.select(). | |
from(item). | |
innerJoin(comment, comment.itemId.eq(item.id)). | |
where(item.done.eq(false)).exec(); | |
}).then(function(results) { | |
results.forEach(function(row) { | |
console.log(row.Item.description, 'before', row.Item.deadline, row.Comment.text); | |
document.body.textContent = | |
row.Item.description + ' before ' + row.Item.deadline + '. ' + row.Comment.text; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment