sangeethailango
How to use postgrex interval datatype
Hey fellow learners,
I have a field called estimated_hours in one of my Ash resource called tasks. I want the datatype of this field to be Postgres interval. I want to calculate how many hours does user wants to complete a task and i will also calculate the sum of these estimated hours.
I found the documentation below from Hex Docs:
I have also searched for Postgres interval datatype and went through the below tutorial.
However, I couldn’t figure out how to apply it in my Ash resource.
Please help me to find out how I can do it.
Most Liked
zachdaniel
Hello!
So in Ash, the primary drive for this would be a custom type. Something like:
defmodule MyApp.Interval do
use Ash.Type
def storage_type(_), do: :interval # you'll have to experiment with what the appropriate storage_type is here
# define cast_input, cast_stored, dump_to_native
end
I haven’t wrapped a built in Postgrex type in quite some time, but take a look at the docs for Ash.Type for info on defining a custom type, that may be enough to get it over the line ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








