Ecto: Interval Type Missing

Created on 23 Jun 2016  路  5Comments  路  Source: elixir-ecto/ecto

Precheck

Been searching online, able to specify :interval for the type in the migration, and it seems an Ecto.Interval type used to exist, but it no longer seems to exist.

Environment

  • Elixir version: 1.3.0
  • Database and version: PostgreSQL 9.4
  • Ecto version: 2.0.1
  • Database adapter and version: Phoenix_ecto 3.0.0, postgrex 0.11.2
  • Operating system: Win10 and Ubuntu 16.04

    Current behavior

# Migration:
  create table(:testing) do
    add :renewal_period, :interval
  end
# Schema
  schema "testing" do
    field :renewal_period, xxx
  end

In place of xxx have tried Ecto.DateTime (does not work since Postgres Interval required %{"months", "days", "seconds"}), Postgrex.Interval (error, unknown Ecto type), Ecto.Interval (error, does not exist), :interval (error, unknown Ecto type), and others all to no avail.

Expected behavior

Assuming Ecto.Interval existed like it used to according to google then this should work:

# Schema
  schema "testing" do
    field :renewal_period, Ecto.Interval
  end

Most helpful comment

have you posted your interval custom ecto type online anywhere?

@axelson Nope, but I could, it is a simple single-file implementation with no docs or anything (mostly from the original Ecto version but with more additions). I just stripped it out of my main project and put it into its own little library at: https://hex.pm/packages/ecto_interval

Just use the type of EctoInterval. PR's welcome as it is entirely untested since pulled out (but simple enough that there should not be any issues anyway).

All 5 comments

@OvermindDL1 you can define your own interval type. Look at Ecto docs about defining your own types. There are no plans for supporting Ecto.Interval directly in Ecto for now.

Already have for now, just curious as to if I were missing something since Intervals seem that they used to be implemented but are not now and not found the reason for removal yet. :-)

@OvermindDL1 have you posted your interval custom ecto type online anywhere?

have you posted your interval custom ecto type online anywhere?

@axelson Nope, but I could, it is a simple single-file implementation with no docs or anything (mostly from the original Ecto version but with more additions). I just stripped it out of my main project and put it into its own little library at: https://hex.pm/packages/ecto_interval

Just use the type of EctoInterval. PR's welcome as it is entirely untested since pulled out (but simple enough that there should not be any issues anyway).

Thanks! I'll check it out!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stavro picture stavro  路  4Comments

ericmj picture ericmj  路  3Comments

atsheehan picture atsheehan  路  4Comments

ZhengQingchen picture ZhengQingchen  路  4Comments

AndresOsinski picture AndresOsinski  路  5Comments