Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Support for fragments in {table, schema} tuple

26 views
Skip to first unread message

Benjamin Milde

unread,
Jan 17, 2025, 11:14:15 AMJan 17
to elixir-ecto
Working with sqlite I created a schema for `pragma_table_info(?)`. But in a query I can either use `fragment("pragma_table_info(?)", table_name)` or `{"pragma_table_info('hardcoded_table_name')", Schema}`. I'm wondering if there could be an API to make an arbitrary source in a query be mapped to a given schema.

benjamin...@gmail.com

unread,
Mar 5, 2025, 12:46:57 PMMar 5
to elixir-ecto
From the top of my head, I think leveraging the https://hexdocs.pm/elixir/Collectable.html and https://hexdocs.pm/elixir/Enumerable.html with https://github.com/elixir-dbvisor/sql might be able to solve this elegantly.

You could use the enumerable example in the readme and implement a collectable for your schema to map the result, or convert the column from string to atom and leverage struct/2.

Reply all
Reply to author
Forward
0 new messages