Created
September 14, 2018 10:50
-
-
Save sorsaffari/c496df88af2b4024206ab7c27b5d2bd4 to your computer and use it in GitHub Desktop.
Phone Calls | Loading Data: template to construct insert query for a person
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
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