Ecto: Support fragments in update

Created on 12 Jun 2016  路  7Comments  路  Source: elixir-ecto/ecto

Environment

  • Elixir version (elixir -v): 1.2.1
  • Database and version (PostgreSQL 9.4, MongoDB 3.2, etc.): 9.4.5
  • Ecto version (mix deps): 1.1.8
  • Database adapter and version (mix deps): postgrex 0.11.1
  • Operating system: ubuntu 14.04

    Current behavior

There's no way to do the use more sophisticated DB features because there's no way to do the following

from(f in File, where: f.id == ^record.id)
  |> MyApp.Repo.update_all(set: [search_vector: fragment("to_tsvector('simple', coalesce(unaccent(?), ''))", keywords)])

Expected behavior

There's a way to pass fragment to the update.

Documentation Starter

Most helpful comment

:heart: :green_heart: :blue_heart: :yellow_heart: :purple_heart:

All 7 comments

Which error do you get?

AFAIR undefined function fragment

That is because update_all is not a macro and does not allow for query syntax.

You can use that, though with update: keyword for from:

query =
  from f in File, where: f.id == ^record_id, update: [set: [foo: fragment("...")]]

Repo.update_all(query, [])

An example in the docs for that would be great!

I can handle this issue, if y'all give the go ahead. :-)

Please go ahead :D

Ready for review, friends!

:heart: :green_heart: :blue_heart: :yellow_heart: :purple_heart:

Was this page helpful?
0 / 5 - 0 ratings