Storing epoch time using timestamps macro

111 views
Skip to first unread message

Geoff Simonds

unread,
May 4, 2016, 9:29:39 AM5/4/16
to elixir-ecto
Good morning.

We are interested in storing the epoch time in our ecto tables/models rather than the default Ecto.DateTime.  Is there a way to accomplish this using @timestamps_opts?

Thanks for any help.

Geoff

José Valim

unread,
May 4, 2016, 9:37:16 AM5/4/16
to elixi...@googlegroups.com
I have literally just pushed a functionality to Ecto master that allows that. You will need something like this:

    @timestamps_opts [type: :integer, autogenerate: {SomeMod, :function, []}]

Where you should implement SomeMod.function() so it returns the epoch time you desired when invoked.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/a6957358-96d9-4eee-a094-a9db9a3bd095%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Geoff Simonds

unread,
May 4, 2016, 10:38:57 AM5/4/16
to elixir-ecto, jose....@plataformatec.com.br
Great, thanks José.

We are currently required to use Sql Server as a backend for Ecto and are therefore using the Tds.Ecto adapter, which doesn't appear to compile using Ecto 2.  Do you have plans to incorporate the changes into the pre 2 branches?

Geoff

José Valim

unread,
May 4, 2016, 11:13:03 AM5/4/16
to elixi...@googlegroups.com
No, there are no plans but you can implement this on 1.x as well. You won't be able to use the timestamps function but you should be able to provide the same functionality by defining the fields as integers and using callbacks.



José Valim
Skype: jv.ptec
Founder and Director of R&D

Reply all
Reply to author
Forward
0 new messages