Last active
September 21, 2018 09:24
-
-
Save sorsaffari/8323495ece21277557f42b6a852a98f0 to your computer and use it in GitHub Desktop.
Grakn with Node.js: Match query - example #1
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
const Grakn = require("grakn"); | |
const grakn = new Grakn("localhost:48555"); | |
const session = grakn.session("phone_calls"); | |
ExecuteMatchQuery(); | |
async function ExecuteMatchQuery() { | |
const tx = await session.transaction(Grakn.txType.READ); | |
let query = [ | |
"match", | |
" $customer isa person has phone-number $phone-number;", | |
' $company isa company has name "Telecom";', | |
" (customer: $customer, provider: $company) isa contract;", | |
' $target isa person has phone-number "+86 921 547 9004";', | |
" (caller: $customer, callee: $target) isa call has started-at $started-at;", | |
" $min-date == 2018-09-14T17:18:49; $started-at > $min-date;", | |
"get $phone-number;" | |
]; | |
console.log("\nQuery:\n", query.join("\n")); | |
query = query.join(""); | |
const iterator = await tx.query(query); | |
const answers = await iterator.collect(); | |
const result = await Promise.all( | |
answers.map(answer => | |
answer | |
.map() | |
.get("phone-number") | |
.value() | |
) | |
); | |
console.log("\nResult:\n", result); | |
await session.close(); | |
process.exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment