Skip to content

Instantly share code, notes, and snippets.

@jz5
Created August 3, 2014 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jz5/f496a5f31716a5d4d312 to your computer and use it in GitHub Desktop.
Save jz5/f496a5f31716a5d4d312 to your computer and use it in GitHub Desktop.
// スキーマ定義
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