Created
January 28, 2010 07:52
-
-
Save pifantastic/288536 to your computer and use it in GitHub Desktop.
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
/* | |
Schema | |
CREATE TABLE dinosaurs ( | |
"name" TEXT, | |
"flying" BOOL, | |
"extinct" BOOL | |
); | |
*/ | |
seltzer.init({ | |
database: "database.sqlite.db" | |
}); | |
// Create a new dino | |
var rawr = seltzer.factory("dinosaurs"); | |
rawr.name = "Megablast Coolson"; | |
rawr.flying = true; | |
rawr.save(); | |
// Get all dinos | |
var dinosaurs = seltzer.factory("dinosaurs").findAll(); | |
// Find a dino by ID | |
var clever_girl = seltzer.factory("dinosaurs").find(1); | |
// Find all dinos matching a where clause | |
var pterosaurs = seltzer.factory("dinosaurs").where({flying: true}).findAll(); | |
for (var x = 0; x < pterosaurs.length; x++) { | |
console.log(pterosaurs[x].name); | |
} | |
// Find the first dino matching a where clause and update it | |
var pterry = seltzer.factory("dinosaurs").where({name: "Pterry"}).find(); | |
var pterry.extinct = false; // yay!! | |
pterry.save(); | |
// Find the first dino matching a where clause and delete it | |
var trex = seltzer.factory("dinosaurs").where({name: "T-Rex"}).find(); | |
trex.del(); // yay!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment