-
Notifications
You must be signed in to change notification settings - Fork 151
Aura example #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aura example #594
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -405,6 +405,73 @@ describe('#integration examples', () => { | |
expect(await consoleLoggedMsg).toEqual(personName) | ||
}) | ||
|
||
it('driver introduction example', async () => { | ||
const console = consoleOverride | ||
const consoleLoggedMsg = consoleOverridePromise | ||
|
||
// tag::driver-introduction-example-imports[] | ||
const neo4j = require('neo4j-driver') | ||
// end::driver-introduction-example-imports[] | ||
|
||
// tag::driver-introduction-example-variables[] | ||
/* | ||
const uri = '%%BOLT_URL_PLACEHOLDER%%'; | ||
const user = '<Username for Neo4j Aura database>'; | ||
const password = '<Password for Neo4j Aura database>'; | ||
*/ | ||
// end::driver-introduction-example-variables[] | ||
|
||
// tag::driver-introduction-example[] | ||
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password)) | ||
const session = driver.session() | ||
|
||
const person1Name = 'Alice' | ||
const person2Name = 'David' | ||
|
||
try { | ||
// To learn more about the Cypher syntax, see https://neo4j.com/docs/cypher-manual/current/ | ||
// The Reference Card is also a good resource for keywords https://neo4j.com/docs/cypher-refcard/current/ | ||
const writeQuery = `MERGE (p1:Person { name: $person1Name }) | ||
MERGE (p2:Person { name: $person2Name }) | ||
MERGE (p1)-[:KNOWS]->(p2) | ||
RETURN p1, p2` | ||
|
||
// Write transactions allow the driver to handle retries and transient errors | ||
const writeResult = await session.writeTransaction(tx => | ||
tx.run(writeQuery, { person1Name, person2Name }) | ||
) | ||
writeResult.records.forEach(row => { | ||
console.log( | ||
`Created friendship between: ${row.get('p1').properties.name}, ${ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also nitpick, could be more clear if we use intermediate node variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense |
||
row.get('p2').properties.name | ||
}` | ||
) | ||
}) | ||
|
||
const readQuery = `MATCH (p:Person) | ||
WHERE p.name = $personName | ||
RETURN p.name AS name` | ||
const readResult = await session.readTransaction(tx => | ||
tx.run(readQuery, { personName: person1Name }) | ||
) | ||
readResult.records.forEach(row => { | ||
console.log(`Found person: ${row.get('name')}`) | ||
}) | ||
} catch (error) { | ||
console.error('Something went wrong: ', error) | ||
} finally { | ||
await session.close() | ||
} | ||
|
||
// Don't forget to close the driver connection when you're finished with it | ||
await driver.close() | ||
// end::driver-introduction-example[] | ||
|
||
expect(await consoleLoggedMsg).toEqual( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this part isn't visible in Aura page? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeh, so it'll only include what's between these lines:
and
This is how we pull in the samples on the Aura side:
That's pointing at my branch at the moment, but I'll update it to use the official repo after it's merged. |
||
`Created friendship between: ${person1Name}, ${person2Name}` | ||
) | ||
}) | ||
|
||
it('read write transaction example', async () => { | ||
const console = consoleOverride | ||
const consoleLoggedMsg = consoleOverridePromise | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but record is perhaps clearer than row
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated row -> record