Skip to content

Commit 0442de0

Browse files
gjmwoodsbigmontz
authored andcommitted
Add transaction configuration examples (#753)
1 parent 1974993 commit 0442de0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/examples.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,66 @@ describe('#integration examples', () => {
810810
])
811811
}, 60000)
812812

813+
it('configure transaction timeout', async () => {
814+
const console = consoleOverride
815+
const consoleLoggedMsg = consoleOverridePromise
816+
const driver = driverGlobal
817+
const personName = 'Antonio'
818+
819+
// Create a person node
820+
function addPerson (tx, name) {
821+
return tx.run('CREATE (a:Person {name: $name}) RETURN a', { name: name })
822+
}
823+
824+
// tag::transaction-timeout-config[]
825+
const session = driver.session()
826+
try {
827+
const result = await session.writeTransaction(
828+
tx => addPerson(tx, personName),
829+
{ timeout: 10 }
830+
)
831+
832+
const singleRecord = result.records[0]
833+
const createdNodeId = singleRecord.get(0)
834+
835+
console.log('Created node with id: ' + createdNodeId)
836+
} finally {
837+
await session.close()
838+
}
839+
// end::transaction-timeout-config[]
840+
expect(await consoleLoggedMsg).toContain('Created node with id')
841+
}, 60000)
842+
843+
it('configure transaction metadata', async () => {
844+
const console = consoleOverride
845+
const consoleLoggedMsg = consoleOverridePromise
846+
const driver = driverGlobal
847+
const personName = 'Antonio'
848+
849+
// Create a person node
850+
function addPerson (tx, name) {
851+
return tx.run('CREATE (a:Person {name: $name}) RETURN a', { name: name })
852+
}
853+
854+
// tag::transaction-metadata-config[]
855+
const session = driver.session()
856+
try {
857+
const result = await session.writeTransaction(
858+
tx => addPerson(tx, personName),
859+
{ metadata: { applicationId: '123' } }
860+
)
861+
862+
const singleRecord = result.records[0]
863+
const createdNodeId = singleRecord.get(0)
864+
865+
console.log('Created node with id: ' + createdNodeId)
866+
} finally {
867+
await session.close()
868+
}
869+
// end::transaction-metadata-config[]
870+
expect(await consoleLoggedMsg).toContain('Created node with id')
871+
}, 60000)
872+
813873
it('use another database example', async () => {
814874
if (protocolVersion < 4.0 || edition !== 'enterprise') {
815875
return

0 commit comments

Comments
 (0)