jwfearn
jwfearn

Reputation: 29627

How to select without a table in Ecto?

How do I do a very simple SQL SELECT query in Ecto that does not use a table?

For example, using the MySQL command-line client, I can do this:

mysql> select 0;
+---+
| 0 |
+---+
| 0 |
+---+
1 row in set (0.00 sec)

How would I do the same in Ecto? Maybe something like this?

q = ... # some no-op queryable?
MyApp.Repo.one(q, select: 0)

Upvotes: 1

Views: 552

Answers (1)

Tiago Engel
Tiago Engel

Reputation: 3661

You can use the Ecto.Adapters.SQL module.

Ecto.Adapters.SQL.query!(MyApp.Repo, "select 0", [])

Upvotes: 3

Related Questions