Created
December 22, 2015 11:59
-
-
Save yakumuka66/441a9205a39e8bb3ca28 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
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