-
-
Notifications
You must be signed in to change notification settings - Fork 441
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
How to use NodaTime to interact with PostgreSQL date/time types? #1027
Comments
@AKlaus There's already a pull request (with some breaking tests) to update us to Npgsql 4 and that'll be ready soon. As for NodaTime w/ Marten, just be aware that you may not be able to use Linq against the NodaTime objects w/o some customizations. A way to do this now is to still have raw DateTime or DateTimeOffset values persisted in the JSON serialization and do the NodaTime object creation in your document objects |
NodaTime support is new and was only added in Npgsql 4. Until this new version is supported, continue using regular DateTime as before. |
Is npgsql v4 support as of marten v2.9+? |
https://www.nuget.org/packages/Marten/3.0.0-alpha-1 has support for npgsql
v4.
Also you can look at branch https://github.com/JasperFx/marten/tree/3.0
…On Mon 20 Aug, 2018, 8:25 PM Sean Farrow, ***@***.***> wrote:
Is npgsql v4 support as of marten v2.9+?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1027 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACu0UGJ6PqND76uwtVwmV4wnQzDM2F-Hks5uSs34gaJpZM4Ub9Kj>
.
|
Is there a way to extend the available types for querying?
I notice there are query handlers but wondered whether these can be added to using something like MEF?
From: Babu Annamalai <notifications@github.com>
Sent: 20 August 2018 16:06
To: JasperFx/marten <marten@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Comment <comment@noreply.github.com>
Subject: Re: [JasperFx/marten] How to use NodaTime to interact with PostgreSQL date/time types? (#1027)
https://www.nuget.org/packages/Marten/3.0.0-alpha-1 has support for npgsql
v4.
Also you can look at branch https://github.com/JasperFx/marten/tree/3.0
On Mon 20 Aug, 2018, 8:25 PM Sean Farrow, ***@***.***> wrote:
Is npgsql v4 support as of marten v2.9+?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1027 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACu0UGJ6PqND76uwtVwmV4wnQzDM2F-Hks5uSs34gaJpZM4Ub9Kj>
.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1027 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fvKSVqHKt-U8iuEGtWyYXI-Sn8Psks5uStBxgaJpZM4Ub9Kj>.
|
MEF? Ick;) You might be able to query as is on properties of the NodaTime objects themselves, or this: http://jasperfx.github.io/marten/documentation/documents/advanced/customizing_linq/ |
Ok, given the below, I think this is doable.
I’m assuming an extension package would be the best way to integrate this?
From: Jeremy D. Miller <notifications@github.com>
Sent: 21 August 2018 11:44
To: JasperFx/marten <marten@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Comment <comment@noreply.github.com>
Subject: Re: [JasperFx/marten] How to use NodaTime to interact with PostgreSQL date/time types? (#1027)
MEF? Ick;)
You might be able to query as is on properties of the NodaTime objects themselves, or this: http://jasperfx.github.io/marten/documentation/documents/advanced/customizing_linq/
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1027 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fqalJX2zPnmzfRT6SHr6GGnAhkbWks5uS-RfgaJpZM4Ub9Kj>.
|
I think that without changes to Marten codebase it won’ Work, I tried some time ago. I’ll revisit that while we have now new Npgsql with NodaTime support. |
Nodatime has a serializer that allows serialization to Json using Json.net.
I don’t know whether this would make a difference?
From: Oskar Dudycz <notifications@github.com>
Sent: 28 September 2018 18:09
To: JasperFx/marten <marten@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Comment <comment@noreply.github.com>
Subject: Re: [JasperFx/marten] How to use NodaTime to interact with PostgreSQL date/time types? (#1027)
I think that without changes to Marten codebase it won’ Work, I tried some time ago. I’ll revisit that while we have now new Npgsql with NodaTime support.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1027 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fvIoIaHlHXVZB6UGoPsX9VPhv8tjks5ufle5gaJpZM4Ub9Kj>.
|
When I was checking it the last itme the biggest issue lied with the Expressions in .NET. They're strongly typed and even if at the end it'd be to construct proper query then it was stating that PG doesn't know this type. So at that time Npgsql was "biggest blocker". Now it's resolved and I can continue. I'm thinking about giving some extensible mechanism for TypeMappings - for sure there some tweaks will be needed. But to sum up - it's doable. I'm using NodaTime in my commercial project, so I'm personally interested on that ;) I'll try to work on that asap. |
Cool, if you need some help/testing let me know.
From: Oskar Dudycz <notifications@github.com>
Sent: 28 September 2018 18:40
To: JasperFx/marten <marten@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Comment <comment@noreply.github.com>
Subject: Re: [JasperFx/marten] How to use NodaTime to interact with PostgreSQL date/time types? (#1027)
When I was checking it the last itme the biggest issue lied with the Expressions in .NET. They're strongly typed and even if at the end it'd be to construct proper query then it was stating that PG doesn't know this type. So at that time Npgsql was "biggest blocker". Now it's resolved and I can continue.
I'm thinking about giving some extensible mechanism for TypeMappings<https://github.com/JasperFx/marten/blob/f66dca0e805a4ea398730766bcf552096591484e/src/Marten/Util/TypeMappings.cs> - for sure there some tweaks will be needed.
But to sum up - it's doable. I'm using NodaTime in my commercial project, so I'm personally interested on that. I'll try to work on that asap.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1027 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fsFxSgdBuj_s8KdxBcqYxOVIsGNJks5ufl7kgaJpZM4Ub9Kj>.
|
I placed the issue on Npgsql that would be imho good first step to push it forward. |
Just to let you all know I'm working right now on the initial support for NodaTime, it will take me some time, as there are few places that I need to update and align implementation. I plan to do it simmilarly as Npgsql as new package Marten.NodaTime. I hope that I'll be able to provide PR for within one week. |
It's still in progres, but feel free to comment the main idea in WIP pull request https://github.com/JasperFx/marten/pull/1154/files |
As I got back to NodaTime support topic. It appears to be an issue with supporting DateTime handling when NodaTime is turned on. So I'd like to have to go with the same way as it's on Npgsql - so you use either DateTime or NodaTime. EF behaves the same afaik. It comes from the Npgsql implementation. The default datetime handlers are internal, so I can't reuse them. I could write our own custom datetime mapper, but then we'll probably end up with the case as we had with Npgsql 4.x and TypeMappings. It would be probably painful maitainance. |
If we go with what you propose, how could nodatime be used?
Could we not map to ticks, nodatime exposes that.
From: Oskar Dudycz <notifications@github.com>
Sent: 21 February 2019 17:26
To: JasperFx/marten <marten@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Comment <comment@noreply.github.com>
Subject: Re: [JasperFx/marten] How to use NodaTime to interact with PostgreSQL date/time types? (#1027)
As I got back to NodaTime support. It appears to be an issue with supporting DateTime handling when NodaTime is turned on. So I'd like to have to go with the same way as it's on Npgsql - so you use either DateTime or NodaTime. EF behaves the same afaik.
Is anyone against that?
It comes from the Npgsql implementation. The default datetime handlers are internal, so I can't reuse them. I could write our own custom datetime mapper, but then we'll probably end up with the case as we had with Npgsql 4.x and TypeMappings. It would be probably painful maitainance.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1027 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fm2cTKRHnmaDQzz1G_JsjpN_9VQAks5vPtbBgaJpZM4Ub9Kj>.
|
I plan to release new package:
When you did that then you won't be able to use So you'll opt out from using .NET (date) time types. Oh well, saving and loading document will work, querying by dates might fail. Event query like:
should work, but Migration won't be needed in most cases, only Types replacement in .NET code. The only migration case that I see is when you used collection with interface in your model - so eg. This concept is aligned with how it's done on |
What do you intend the UseNodatime extension method doing?
How is date/time comparison handled in queries currently? I wonder whether we could abstract this somehow and use a strategy?
From: Oskar Dudycz <notifications@github.com>
Sent: 21 February 2019 17:37
To: JasperFx/marten <marten@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Comment <comment@noreply.github.com>
Subject: Re: [JasperFx/marten] How to use NodaTime to interact with PostgreSQL date/time types? (#1027)
I plan to release new package: Marten.NodaTime. It will add new extension method to store options. You could do just:
DocumentStore.For(_ =>
{
_.UseNodaTime();
});
When you did that then you won't be able to use DateTime, you'll need to use LocalDateTime, LocalDate, Instant etc.
So you'll opt out from using .NET (date) time types.
Oh well, saving and loading document will work, querying by dates might fail. Event query like:
query.Query<TargetWithDates>().FirstOrDefault(d => d.DateTime == dateTime)
should work, but greater or greater or equal or any more sophisticated might fail. In general we won't guarantee that DateTime will work.
Migration won't be needed in most cases, only Types replacement in .NET code. The only migration case that I see is when you used collection with interface in your model - so eg. IEnumerable<DateTime>. If that's an issue, I could prepare some migration tool for that case.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1027 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fiqKkTARP4Y-nAxG8QLL8XiFa-jNks5vPtkpgaJpZM4Ub9Kj>.
|
It will setup everything what's needed for Marten to use NodaTime. So eg. See more in my WIP PR: https://github.com/JasperFx/marten/pull/1154/files#diff-53eb368e074036b2639ff3d740492e30R12 Even if I didn't add this extension method, then you'd still add reference to the |
I’ll have a look at that over the weekend.
Any thoughts on how we can implement queries so they ‘just work’?
Nodatime implements all operators such as equals as one would expect, does this mean we don’t need to do anything?
From: Oskar Dudycz <notifications@github.com>
Sent: 21 February 2019 17:45
To: JasperFx/marten <marten@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Comment <comment@noreply.github.com>
Subject: Re: [JasperFx/marten] How to use NodaTime to interact with PostgreSQL date/time types? (#1027)
It will setup everything what's needed for Marten to use NodaTime. So eg. JsonNetSerializer, JsonLocator, etc.
See more in my WIP PR: https://github.com/JasperFx/marten/pull/1154/files#diff-53eb368e074036b2639ff3d740492e30R12
Even if I didn't add this extension method, then you'd still add reference to the Npgsql.NodaTime package and call it somewhere.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1027 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fi0epVXxwMytSIpRXeZnkp0mGS3Hks5vPtscgaJpZM4Ub9Kj>.
|
The queries will work, exactly the same as they work for |
That looks good, the only remaining question I have is whether any queries with nodatime types as date/times will work at the database or in memory? I’m assuming the latter?
From: Oskar Dudycz <notifications@github.com>
Sent: 21 February 2019 17:56
To: JasperFx/marten <marten@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Comment <comment@noreply.github.com>
Subject: Re: [JasperFx/marten] How to use NodaTime to interact with PostgreSQL date/time types? (#1027)
The queries will work, exactly the same as they work for DateTime currently. Npgsql made the work for custom type mapping, and proper replacing DateTime with NodaTime. See more here: https://www.npgsql.org/doc/types/nodatime.html
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1027 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fiRSX-it7-KT628qiXnnZvOBiPt5ks5vPt2ZgaJpZM4Ub9Kj>.
|
Yes, they should work in both (of course Marten Queryable, have some limitation in dates queries, but this shouldn't be different than current DateTime support). |
Hi guys, just to say that I have my eyes on this discussion. I've received a complaint or two about the inability to mix both NodaTime and BCL date/time types in the same application, but up to now it doesn't seem actually blocking for users. If you have any input or feedback saying otherwise, I'll be happy to listen. |
@roji thank you for the response! TBT I'm not sure if that'll be huge issue for the users. I asked on this issue, on our gitter, @jeremydmiller asked on Twitter, to get initial feedback. Currently noone complains (which is good), but not all users are active on those channels. Imho it might be an effort to refactor the code from .NET types to NodaTime. Gradual update won't be possible because out of the box in Npgsql they can't coexist. Also because we're storing our collections serialized with TypeNames (to be able to deserialize interfaces collections like IEnumerable, IReadonlyCollection etc.) then some data migration will be needed. As a user I'd prefer to have an option but I'm not sure if it's something nessesary. I plan to release the first version of our |
Btw. for all interested. My PR is almost done #1154, I'm waiting for approvals from @jeremydmiller @mysticmind @jokokko. If they give green light then I'll probably add more tests and it will be ready to be released. |
@oskardudycz thanks, keep me posted. If it's really needed I can take a look at what it would involve with the Npgsql type handler model. |
@roji, |
Thank you @roji, I appreciate that 👍 |
PR #1154 with NodaTime support was merged. It will be available in version 3.5.0 that should be released within a week. |
The NodaTime plugin is the recommended way to interact with PostgreSQL date/time types. However, we can't use it along with Martin due to:
Therefore, would be possible to upgrade the Npgsql dependency to v4? Or could you recommend another way of using NodaTime to interact with PostgreSQL date/time types?
The text was updated successfully, but these errors were encountered: