Created
February 12, 2012 17:12
-
-
Save antoniogarrote/1809679 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 mg = require('./../src/micrograph'); | |
exports.inverseProperties = function(test) { | |
mg.create(function(g) { | |
// saving a Person | |
g.save([{$type: 'Person', | |
name: 'Ludwig', | |
surname: 'Wittgenstein', | |
birthplace: 'Wien'}], | |
function(wittgenstein){ | |
// saving some books | |
g.save({$type: 'Book', | |
title: 'The Open Society and its Enemies', | |
// Popper is included as author here | |
author$in: {$type: 'Person', | |
name:'Karl', | |
surname: 'Popper'}, | |
pages: 510}). | |
save({$type: 'Book', | |
title: 'Philosophical Investigations', | |
pages: 320, | |
author$in: wittgenstein.$id}). | |
save({$type: 'Book', | |
title: 'Tractatus Logico-Philosophicus', | |
pages: 120, | |
author$in: wittgenstein.$id}). | |
// all books written by something whose name is not Wittgenstein | |
where({$type: 'Book', | |
author$in: | |
{surname: {$neq: 'Wittgenstein'}}}). | |
execute(function(books){ | |
var titles = {}; | |
for(var i=0; i<books.length; i++) { | |
titles[books[i].title] = true; | |
} | |
test.ok(titles["The Open Society and its Enemies"]); | |
titles = {}; | |
// All books written by Wittgenstein | |
g.where({surname: 'Wittgenstein', | |
author: {}}). | |
each(function(wittgenstein){ | |
for(var i=0; i<wittgenstein.author.length; i++) | |
titles[wittgenstein.author[i].title] = true; | |
}). | |
execute(function(){ | |
test.ok(titles["Philosophical Investigations"]); | |
test.ok(titles["Tractatus Logico-Philosophicus"]); | |
test.done(); | |
}); | |
}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment