railsmechanic

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

Most Liked

sashaafm

sashaafm

This Stackoverflow thread might be of interested and quite simple.

michalmuskala

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.

andre1sk

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.

Last Post!

kylethebaker

kylethebaker

The phoenix generators set you up with ecto by default (unless you pass --no-ecto), but otherwise phoenix doesn’t care about the database/ecto (although Phoenix.Html.Form can use changesets out of the box).

With ecto you can pass raw queries, though it ultimately comes down to the database adapter. You can pass raw sql strings or use the query builder. It’s entirely schema agnostic, though there are a few places that nudge you in a certain direction by providing sensible defaults. In these cases you are always able to override the defaults though.

Where Next? Top

Trending in Questions Top

RSP87
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
nseaSeb
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
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews