Created
August 3, 2014 12:00
-
-
Save jz5/f496a5f31716a5d4d312 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// スキーマ定義 | |
var JSRel = require("jsrel"); | |
var db = JSRel.create("dbname", {schema: | |
{ user: { name : true, is_activated: "on", $uniques: "name"}, | |
book: { title: true, price: 1, author: "user", $indexes: "title" }, | |
}}); | |
// データの挿入 | |
if (!db.loaded) { // if loaded from saved data, omits this section | |
var u1 = db.ins('user', {name: 'shinout'}); | |
var u2 = db.ins('user', {name: 'xxxxx', is_activated: false}); | |
var b1 = db.ins('book', {title: 'how to jsrel', price: 10, author: u1}); | |
var b2 = db.ins('book', {title: 'JSRel API doc', price: 20, author_id: u1.id}); | |
} | |
// データの取得 | |
var users = db.find('user', {is_activated: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment