railsmechanic
Hi Alchemists,
we’re investigating whether the migration of our (simple) Rails API to Phoenix is a viable step for us.
As we can’t migrate the Rails database schema to ecto, I’m interested in how to use Phoenix just with raw SQL queries. Is it recommended to drop ecto and setup the database connection pooling etc. from scratch, or do you recommend to keep ecto because of all the great things like connection pooling etc.?
Long story short:
How to use Phoenix just with raw SQL queries? Are there any examples about that subject?
Many thanks
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sashaafm
This Stackoverflow thread might be of interested and quite simple.
dgamidov
@railsmechanic, you will loose a lot of cool things without ecto.
Check this video:
andre1sk
If you opt for stored procedures as opposed to using raw queries you will actually gain a lot of flexibility compared to using ORM.
railsmechanic
I know, but a complete migration to ecto is not possible at the moment.
benwilson512
It’s also worth noting that Phoenix has nothing to do with this at all, it is merely a web framework.
What prevents you from migrating the rails schema to ecto?
railsmechanic
I know that Phoenix is “just” a web framework, but I don’t want to reinvent the wheel by writing my own database connection pool and stuff etc. Before doing this, I just wanted to know whether a default Phoenix respectively ecto installation is able to execute raw SQL queries without the need to setup models/schemas.
The reason for all this is, as we cannot migrate the rails schema to ecto at the moment, because our customer is using the underlying database from other systems which don’t belong to us. Otherwise we’ve already migrated the service.
themarlzy
As someone who hasn’t really used Rails / ORM before, I don’t understand the benefits. Whenever I see the convoluted Ecto code, I just think “isn’t it easier to just write the SQL?”. I don’t buy the portability argument - if you want to change from mySQL to postgres, you’re in for some pain, no matter the abstraction.
I’m admittedly naive to the pros of this, given the lack of experience with the tools.
Curious to hear how one would utilise raw SQL.
M
michalmuskala
You can look at the drivers: GitHub - elixir-ecto/postgrex: PostgreSQL driver for Elixir · GitHub and
GitHub - xerions/mariaex: Pure Elixir database driver for MariaDB / MySQL · GitHub - they are built on top of db_connection
so they have pooling, transactions support, etc. For postgres you could
also look at GitHub - robconery/moebius: A functional query tool for Elixir · GitHub for postgres that is
closer to SQL.
That said, you don’t need to change anything in your database to be able to
use ecto. You can simply define your schema modules and skip migrations.
I’ve heard couple stories of ecto working fine with a rails database.
michalmuskala
I agree that the argument of changing the database is completely
nonsensical. I have yet to see a system that does not use any
database-specific queries.
I see the strength of ecto in different areas - changesets are extremely
powerful and convenient way to work with data in general, not necessarily
database-originating data. Custom type definitions and automatic casting
make it a breeze to build systems. There are also some additional features
around handling associations, properly parametrizing queries, etc. Making
queries composeable is also a powerful idea that simplifies code
tremendously.
While I could definitely live without queries and write raw SQL,
abstractions such as changesets, multi and types are definitely a huge
improvement.
railsmechanic
Many thanks, moebius looks surprising…