Skip to content
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

Add support for Elixir Durations #696

Merged
merged 3 commits into from
Jul 26, 2024

Conversation

greg-rychlewski
Copy link
Member

@greg-rychlewski greg-rychlewski commented Jul 26, 2024

Addresses #688 besides the deprecation of Postgrex.Interval.

The following changes were made:

  • allow encoding of Duration structs for postgres interval extension
  • allow decoding postgres interval types to Duration structs if the option :interval_decode_type is set to Duration
  • both of the above two are only allowed if the elixir version is at least 1.17.0

Some notes:

  • when breaking down the postgres response (microseconds, days and months) into the fields for the Duration struct, I went with the same style we use for Postgrex.Interval: translate the lower units into the higher units as much as possible
  • the type modifier postgres returns for intervals is not an integer from 0 to 6. i will try to find out what it means but it's not well documented so probably have to go through their source code. for now i always return precision of 6 because they are giving us microseconds in the response
  • from what i can see we are not documenting anywhere the options that can be passed to any of our extensions. in a follow-up PR i'll try to collect them all and put them in a good place

@greg-rychlewski greg-rychlewski merged commit 3e9ea98 into elixir-ecto:master Jul 26, 2024
9 checks passed
@greg-rychlewski greg-rychlewski deleted the elxir_duration branch July 26, 2024 11:44
@greg-rychlewski
Copy link
Member Author

Would you want to add a :duration type to ecto?

@josevalim
Copy link
Member

We should! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants