What is the aliases used for in SelectExpr.

10 views
Skip to first unread message

benjamin...@gmail.com

unread,
Nov 28, 2024, 4:35:13 PM11/28/24
to elixir-ecto
Hi there,

Can anyone tell me what the aliases are used for in SelectExpr? Currently, it's always an empty map.

I'm asking because I'm working on making the SQL sigil convert back and forth from sigil to Ecto.Query.

José Valim

unread,
Nov 28, 2024, 4:36:38 PM11/28/24
to elixi...@googlegroups.com
Not at the computer. But perhaps for as(value, :name) and parent_as(value, :name) feature used to name select fields?


--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/elixir-ecto/fd20dbc9-c3d5-47bb-bc52-f2b30605130en%40googlegroups.com.

benjamin...@gmail.com

unread,
Nov 28, 2024, 5:16:57 PM11/28/24
to elixir-ecto
Thanks, you are correct. Seams like Ecto DSL are almost one-to-one with regular SQL, besides all the functions that would require fragments.

It should still be possible to translate back and forth. Still, the more I think about it, the better it might be to separate the mapping to struct and eventual preloading of associating for sigils instead of relying on Ecto.Query to do it.

```
iex> ~SQL[select id, email from users] |> Ecto.SQL.into(User)
iex> %User{id:1, email: jo...@example.com}
```
Reply all
Reply to author
Forward
0 new messages