Skip to content

Instantly share code, notes, and snippets.

@yakumuka66
Created December 22, 2015 11:59
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 yakumuka66/441a9205a39e8bb3ca28 to your computer and use it in GitHub Desktop.
Save yakumuka66/441a9205a39e8bb3ca28 to your computer and use it in GitHub Desktop.
console.log(db._version());
db._create('test');
db.test.save({ _key: "1", value: "foo" });
db.test.save({ _key: "2", value: [ "foo", "bar" ] });
function test(r) {
const query = r[0];
const expect = r[1];
const actual = db._query(query).toArray().sort().join(',');
const result = actual == expect ? 'PASSED' : 'FAILED';
console.log(query);
console.log(result, '--', 'expect:', expect, 'actual:', actual);
}
// double array with query and expected result
const runs = [
[ 'FOR t IN test RETURN t._key', '1,2' ],
[ 'FOR t in test FILTER t.value IN [ "foo" ] RETURN t._key', '1,2' ],
[ 'FOR t in test FILTER "foo" IN t.value RETURN t._key', '1,2' ],
[ 'FOR t in test FILTER t.value[*] IN [ "foo" ] RETURN t._key', '1,2' ],
[ 'FOR t in test FILTER "foo" IN t.value[*] RETURN t._key', '1,2' ],
]
console.log('Testing without indices;');
runs.forEach(test);
console.log('Testing with index;', 'value');
db.test.ensureHashIndex('value');
runs.forEach(test);
console.log('Testing with index;', 'value', 'value[*]');
db.test.ensureHashIndex('value[*]');
runs.forEach(test);
db._drop('test');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment