Created
June 4, 2018 17:34
-
-
Save adam-cowley/284eae06730b787359c4bd54349bdef9 to your computer and use it in GitHub Desktop.
Using Neo4j Temporal data types in Neo4j Drivers
This file contains 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
const neo4j = require('neo4j-driver').v1 | |
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', 'neo')) | |
const session = driver.session() | |
session.run( | |
'CREATE (e:Event { id: $id, title: $title, startsAt: datetime($startsAt) }) RETURN e', | |
{ | |
id: 2, | |
title: 'Another Test Event', | |
startsAt: { | |
year: 2018, | |
month: 01, | |
day: 02, | |
hour: 12, | |
minute: 34, | |
second: 56, | |
timezone: 'Z', | |
}, | |
} | |
) | |
.then(res => { | |
console.log(res.records[0].get('e').properties.startsAt.toString()) | |
}) | |
.then(() => session.close()) | |
.then(() => driver.close()) | |
.catch(e => { | |
console.log(e.stack) | |
}) |
This file contains 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
const neo4j = require('neo4j-driver').v1 | |
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', 'neo')) | |
const session = driver.session() | |
session.run( | |
'CREATE (e:Event { id: $id, title: $title, startsAt: $startsAt }) RETURN e', | |
{ | |
id: 1, | |
title: 'Test Event', | |
startsAt: new neo4j.types.DateTime(2018, 01, 02, 12, 34, 56, 123400000, 'Z') | |
} | |
) | |
.then(res => { | |
console.log(res.records[0].get('e').properties.startsAt.toString()) | |
}) | |
.then(() => session.close()) | |
.then(() => driver.close()) | |
.catch(e => { | |
console.log(e.stack) | |
}) |
This file contains 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
const neo4j = require('neo4j-driver').v1 | |
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', 'neo')) | |
const session = driver.session() | |
session.run( | |
'CREATE (e:Event { id: $id, title: $title, startsAt: datetime($startsAt) }) RETURN e', | |
{ | |
id: 2, | |
title: 'Another Test Event', | |
startsAt: '2018-01-02T12:34:56.1234Z' | |
} | |
) | |
.then(res => { | |
const startsAt = res.records[0].get('e').properties.startsAt | |
console.log('year', startsAt.year.toNumber()) // 2018 | |
console.log('month', startsAt.month.toNumber()) // 01 | |
console.log('day', startsAt.day.toNumber()) // 02 | |
console.log('hour', startsAt.hour.toNumber()) // 12 | |
console.log('minute', startsAt.minute.toNumber()) // 34 | |
console.log('second', startsAt.second.toNumber()) // 56 | |
console.log('nanosecond', startsAt.nanosecond.toNumber()) // 123400000 | |
console.log('toString', startsAt.toString()) // 2018-01-02T12:34:56.123400000Z | |
console.log('date', new Date( startsAt.toString() ) ) | |
}) | |
.then(() => session.close()) | |
.then(() => driver.close()) | |
.catch(e => { | |
console.log(e.stack) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment