Replies: 1 comment 9 replies
-
This type of boiler plate is something we'd like to handle for making the driver easier to integrate to javascript environments. One alternative is work with hydration/dehydration hooks can transform driver objects to domain or some library shape. Some usage example: const driver = neo4j.driver(URL, CREDENTIALS, {
hydrationHooks: {
LocalDateTime: (value: LocalDateTime) => value.toString() // convert to datetime string,
DateTime: (value: DateTime) => fromNeo4jDateTimeToMyFancyLibraryDateTime(value) // converts to the fancy library date time
},
dehydrationHooks: {
DateTime: {
isDateTime: checkIfValueIsFromMyFancyLibraryDateTime, // check if object is from the temporal library you are using
convert: fromMyFancyLibraryDateTimeToNeo4jDateTime // converts to neo4j date time
}
}
}) |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to submit a proposal to convert Neo4 Date and Time object into ISO strings when returning these values from the driver.
The driver returns properties and values, which are defined in Neo4j as DateTime, Date or Time, in their native Java format. That means, the ISO string
1970-01-01T00:00:00.000Z
will be returned as Neo4j DateTime object and serialised into JSON as
However, this format is not very useful when working with JavaScript. I know there are methods like
DateTime.toStandardDate()
to get a plain JS Date, but there are still some drawbacks:the Neo4j database connection is usually abstracted or hidden by a backend layer, that means downstream services receive the serialised JSON format instead of the Neo4j
DateTime
object that provide the conversion functionstoStandardDate()
.other services that receive the data as JSON have to install the neo4j driver package to create a Neo4j
DateTime
object via its constructor and then convert it to a JS Date. Or they have to implement their own function to create a JS Date from this format.the conversion from Neo4j
DateTime
to JSDate
looses timezone information, because JS Date is not timezone aware and always converts dates into local time. The conversion of1970-01-01T00:00:00.000Z
from Neo4j DateTime to JS Date and back to Neo4j DateTime alters the original ISO string and adds a timezone offset of 3600 seconds. Of course, it is still the original date and time, but the timezone information was changed. That is the reason we usually avoid working with the native JS Date and instead use libraries like Luxon, Moment, or Day.js that retain the original timezone.These drawbacks could be solved if the driver would be able to convert the DateTime, Date and Time objects as ISO strings instead of the corresponding objects. For example, as an option
disableTemporalTypes
like the conversion of Neo4j Integers to native JS numbers:Or it could be implemented as
mappedResultTransformer
for the newDriver.executeQuery()
with a conversion function for each native Java type:Conversion of DateTime, Date and Time to ISO strings would also help, because JavaScript Date doesn't support date-only
1970-01-01
and time-only00:00:00.000Z
. In this cases, the conversion to JS Date potentially alters real information.Beta Was this translation helpful? Give feedback.
All reactions