rodloboz
Is there any way to do SQL type inference/value casting when I have a raw SQL statement without having access to the underlying Ecto schemas?
In the Ruby/ActiveRecord world, I’ve used arel_table.type_cast_for_database(attribute_name, value)
So given a column name and a value from the SQL statement, is it possible to do something similar in Elixir (that would work for SQLite, MySQL, Postgres)?
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
At least in postgres you can query
information_schemafor the column type andPostgrex.Types.encodecan encode data to that. There’s afaik no shared functionality. Ecto simply makes it the users responsibility that the ecto types they use work with the database they use.rodloboz
Thanks! That’s a bummer… I’d like to have something that can work across all 3 database types
LostKobrakai
I have no idea how ActiveRecord does it, but postgrex uses the binary protocol of postgres, which is very much a postgres specific format. Nothing in that process ever converts the value to a string/text format.
dimitarvp
Not really, because they are way too different (as @LostKobrakai pointed out,
postgrexuses Postgres’ binary protocol and many other drivers in other programming languages don’t). It works in ActiveRecord because likely because somebody put on the elbow grease to have a branching code… the same one you would invent yourself if you chase after this further.To shill a little bit for myself again: when I finally overcome my being extremely busy and tired to deal with the final issue of CI workers running out of memory on machines with 92% free memory, I’ll release my SQLite3 thing that has a ton of introspection and makes writing the wiring you need trivial. But that’s an announcement for a weeks from now (hopefully not months but oh well, I’ve been saying this for like two months now so…).
Schultzer
Lol, thats what I’m building GitHub - elixir-dbvisor/sql: SQL provides state-of-the-art, high-performance SQL integration for Elixir, built to handle extreme concurrency with unmatched expressiveness and ergonomic query composition. Write safe, composable, parameterized queries directly, without translating to Ecto or any ORM. · GitHub
rodloboz
Does it already handle casting? I could use something like that in GitHub - elixir-lotus/lotus: Embeddable business intelligence engine for Elixir — SQL editor, dashboards, charts, and AI query generation that mount directly in your Phoenix app. · GitHub
Right now my pain point is that in the web UI users can defined variables which can be filled in with values in widget inputs. The inputs only have 3 types: number, text, or dates.
Then when you submit a query with these variables the core lib makes the param substitution. It works fine until I have something like UUID, which is the case in the app I’ve built Lotus for
So what I’m doing is converting the binary format to a user-friendly string to display in the UI, so it makes sense that variables receive these same converted strings. But then I would need to cast it back to the native binary format and I can’t find a good way to infer the column type for casting.
Schultzer
It does not support this right now, but this is the target for 0.5. 0.4 is getting closer but still a bit out, as we’re improving runtime performance to make it faster then Ecto, regardless of you using the sigil or call the underlying functions.
rodloboz
Thanks, that look promising.
I might try rewriting parts of my code with it as it seems like it could replace some transformations I’m doing ad-hoc by calling its underling functions – the sigil won’t be so useful in my lib as the SQL statements are coming from the UI.
If it was able to do runtime inference for casting then it would really support my use case. I’ll keep an eye on it
Schultzer
With our architecture it will be trivial to add runtime inference and casting. And we will eventually provide a simple API so you don’t have to fiddle with the underlying modules.
But feel free to play around with it, any kind of feedback is appreciated!