Skip to content

Instantly share code, notes, and snippets.

@sorsaffari
Last active September 21, 2018 09:26
Show Gist options
  • Save sorsaffari/6f09b8434985611ea79c14698d1ca464 to your computer and use it in GitHub Desktop.
Save sorsaffari/6f09b8434985611ea79c14698d1ca464 to your computer and use it in GitHub Desktop.
Grakn with Node.js: Match query - example #3
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 ",
" $common-contact isa person has phone-number $phone-number;",
' $customer-a isa person has phone-number "+7 171 898 0853";',
' $customer-b isa person has phone-number "+370 351 224 5176";',
" (caller: $customer-a, callee: $common-contact) isa call;",
" (caller: $customer-b, callee: $common-contact) isa call;",
"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