Last active
September 21, 2018 09:28
-
-
Save sorsaffari/8c7b5ad6b796f91e5603951ca8bb4937 to your computer and use it in GitHub Desktop.
Grakn with Node.js: Match query - example #4
This file contains 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 ", | |
' $target isa person has phone-number "+48 894 777 5173";', | |
' $company isa company has name "Telecom";', | |
" $customer-a isa person has phone-number $phone-number-a;", | |
" (customer: $customer-a, provider: $company) isa contract;", | |
" (caller: $customer-a, callee: $target) isa call;", | |
" $customer-b isa person has phone-number $phone-number-b;", | |
" (customer: $customer-b, provider: $company) isa contract;", | |
" (caller: $customer-b, callee: $target) isa call;", | |
" (caller: $customer-a, callee: $customer-b) isa call;", | |
"get $phone-number-a, $phone-number-b;" | |
]; | |
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-a") | |
.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