Hello, I want to convert my Ecto.data
time to unix when I select in data base .
please see my code:
convertor:
def nav_time_to_unix(time_to) do
time_to
|> NaiveDateTime.to_erl
|> :calendar.datetime_to_gregorian_seconds
|> Kernel.-(62167219200)
end
db select:
defp user_fields(query, group_acl) do
from [p, c] in query,
where: p.group_acl in ^group_acl,
where: c.group_acl in ^group_acl,
select: %{
id: p.id,
title: p.title,
create_time: ^nav_time_to_unix(p.inserted_at),
.....
end
but I have an error like this:
== Compilation error in file lib/cms/post/post_query.ex ==
** (Ecto.Query.CompileError) `^(p.inserted_at(), nav_time_to_unix())` is not a valid query expression.
* If you intended to call a database function, please check the documentation
for Ecto.Query to see the supported database expressions
* If you intended to call an Elixir function or introduce a value,
you need to explicitly interpolate it with ^
expanding macro: Ecto.Query.select/3
lib/cms/post/post_query.ex:59: TrangellCmsService.Cms.Post.PostQuery.admin_fields/1
expanding macro: Ecto.Query.from/2
lib/cms/post/post_query.ex:59: TrangellCmsService.Cms.Post.PostQuery.admin_fields/1
could not compile dependency :trangell_cms_service, "mix compile" failed. You can recompile this dependency with "mix deps.compile trangell_cms_service", update it with "mix deps.update trangell_cms_service" or clean it with "mix deps.clean trangell_cms_service"