I'm trying to hash the current ID of every book I insert in the database, so that every book will be recognized by such 'code'.
Is there is a way in Ecto to display value of fragment("nextval('books_id_seq')")
in a changeset or Ecto.insert() ?
So far all I can do is get the last id by calling it from this function :
...
def get_currval() do
from(b in Book,
select: fragment("nextval('books_id_seq')"),
limit: 1
)
|> Repo.one
end
I'd love to have something more reliable, like a fragment in the insert query.