Skip to content

Instantly share code, notes, and snippets.

@sorsaffari
Created September 14, 2018 10:50
Show Gist options
  • Save sorsaffari/c496df88af2b4024206ab7c27b5d2bd4 to your computer and use it in GitHub Desktop.
Save sorsaffari/c496df88af2b4024206ab7c27b5d2bd4 to your computer and use it in GitHub Desktop.
Phone Calls | Loading Data: template to construct insert query for a person
function personTemplate(person) {
const { first_name, last_name, phone_number, city, age } = person;
// insert person
let graqlInsertQuery = `insert $person isa person has phone-number "${phone_number}"`;
const isNotCustomer = typeof first_name === "undefined";
if (isNotCustomer) {
// person is not a customer
graqlInsertQuery += " has is-customer false";
} else {
// person is a customer
graqlInsertQuery += ` has is-customer true`;
graqlInsertQuery += ` has first-name "${first_name}"`;
graqlInsertQuery += ` has last-name "${last_name}"`;
graqlInsertQuery += ` has city "${city}"`;
graqlInsertQuery += ` has age ${age}`;
}
graqlInsertQuery += ";";
return graqlInsertQuery;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment