Closed serialhex closed 6 years ago
The problem is that the underlying datastore has to expose the types being used. I'm not actually quite sure how to make the types defined in this project work with other databases, as they mostly piggyback on Ecto types. You would probably need to conditionally change the behaviour of the type based on what adapter is being used, I think, since what you want is for the representation of that data type to change based on whether the database natively supports that type.
So my recommendation would be to define a custom Ecto type which you can use for DateTimes when running on SQLite, then swap back to the native Ecto types, or the Timex.Ecto types, when using Postgres.
I'm a big fan of SQLite myself, but haven't really found use for it in Elixir yet. My maintenance burden is already pretty well peaked, so I can't really afford to support another database in this project unfortunately :(
I know in the documentation you explicitly say that only Postgres is supported, I thought I might try using timestamps w/ timezone in SQLite. Unfortunately this is a no-go, as I get cool errors[1].
Now, my thinking was that SQLite isn't very type-safe, AFAIK the types mostly just there to help figure out what's going on, and defaults to string. So I was hoping that my
field :timestamp, Timex.Ecto.DateTimeWithTimezone
would stringify to"#DateTime<2018-04-30 15:34:50.897000-04:00 EDT America/New_York>"
or"2018-04-30T15:35:43.300000-04:00"
or something... Not too surprised that this didn't work, but I was wondering what would it take to make it work?OTOH, maybe this isn't a problem with Timex.Ecto, but possibly Ecto itself, or (more likely) my code. It seems like SQLite gets the short-end of the dev-time stick, but IMHO, it's way easier to work with than Postgres, even in production. (Granted, I'm not doing anything web-scale, but then I wouldn't be using Postgres anyway :stuck_out_tongue_closed_eyes: [2])
[1] Cool Error:
[2] https://www.youtube.com/watch?v=b2F-DItXtZs