Skip to content

Limit does not support expressions #42

Open
@troygnichols

Description

@troygnichols

With SQL adapters like postgres you can write something like this:

limit = 42
MyRepo.all(from item in Item, limit: ^limit)

In ecto_mnesia, this produces an error like this:

** (FunctionClauseError) no function clause matching in Enum.take/2
 stacktrace:
   (elixir) lib/enum.ex:2334: Enum.take([[%SellOffer{__meta__: #Ecto.Schema.Metadata<:loaded, "sell_offer">, age: 11, application: nil, book_value: nil, booked_at: nil, dividable: nil, dpc: nil, dpd: nil, ended_at: nil, guaranteed: nil, id: 1, income: nil, inserted_at: ~N[2017-07-02 02:32:52.743812], loan_changes: nil, loan_currency: nil, loan_duration: nil, loan_id: "hello", loan_oap: nil, loan_product_type: nil, loan_risk_class: nil, loan_risk_subclass: nil, loan_status: nil, max_shared_apr: nil, min_price_rate: nil, status: nil, trader_id: nil, updated_at: ~N[2017-07-02 02:32:52.743819]}], [%SellOffer{__meta__: #Ecto.Schema.Metadata<:loaded, "sell_offer">, age: 21, application: nil, book_value: nil, booked_at: nil, dividable: nil, dpc: nil, dpd: nil, ended_at: nil, guaranteed: nil, id: 3, income: nil, inserted_at: ~N[2017-07-02 02:32:52.744109], loan_changes: nil, loan_currency: nil, loan_duration: nil, loan_id: "world", loan_oap: nil, loan_product_type: nil, loan_risk_class: nil, loan_risk_subclass: nil, loan_status: nil, max_shared_apr: nil, min_price_rate: nil, status: nil, trader_id: nil, updated_at: ~N[2017-07-02 02:32:52.744113]}], [%SellOffer{__meta__: #Ecto.Schema.Metadata<:loaded, "sell_offer">, age: 15, application: nil, book_value: nil, booked_at: nil, dividable: nil, dpc: nil, dpd: nil, ended_at: nil, guaranteed: nil, id: 2, income: nil, inserted_at: ~N[2017-07-02 02:32:52.743973], loan_changes: nil, loan_currency: nil, loan_duration: nil, loan_id: "hello", loan_oap: nil, loan_product_type: nil, loan_risk_class: nil, loan_risk_subclass: nil, loan_status: nil, max_shared_apr: nil, min_price_rate: nil, status: nil, trader_id: nil, updated_at: ~N[2017-07-02 02:32:52.743977]}]], {:^, [], [0]})
   (ecto_mnesia) lib/ecto_mnesia/planner.ex:65: EctoMnesia.Planner.execute/6
   (ecto) lib/ecto/repo/queryable.ex:130: Ecto.Repo.Queryable.execute/5
   (ecto) lib/ecto/repo/queryable.ex:35: Ecto.Repo.Queryable.all/4
   test/unit/adapter_test.exs:378: (test)

Limit works fine if you give it a literal like this:

    MyRepo.all(from item in Item, limit: 42)

It's only a problem if you use a ^ expression

Expressions do seem to work for order_by, just not limit, e.g. this works fine:

field = :name
MyRepo.all(from item in Item, order_by: [desc: ^field])

Here are some tests that demonstrate the issue:

troygnichols@ae0a038

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions