ycv005

ycv005

Ecto query into Plain SQL

How to convert following Ecto Query into the Plain RAW SQL

%Workspace{name: "#{prefix() || "public"}"} |> Repo.insert()

Your response will be highly appreicable.

First Post!

alexiss

alexiss

regarding docs:

Ecto.Adapters.SQL.to_sql(:insert, Repo, %Workspace{name: "#{prefix() || "public"}"})

UPD sorry - :insert is not supported (

Most Liked

mxgrn

mxgrn

Wow, I just found GitHub - akoutmos/ecto_dbg: A utility to format and output Ecto queries · GitHub

It produces well-formatted, copy-paste-ready SQL right into my logs :heart::heart::heart: @akoutmos

LostKobrakai

LostKobrakai

Did you try it?

It’s documented here: ecto_sql/lib/ecto/adapters/sql.ex at 2ec71d74655cc076b6c965740a357dfe1505883a · elixir-ecto/ecto_sql · GitHub and here’s the macro, which adds it to the repo: ecto_sql/lib/ecto/adapters/sql.ex at 2ec71d74655cc076b6c965740a357dfe1505883a · elixir-ecto/ecto_sql · GitHub

It’s not part of the Ecto.Repo behaviour though, which is why it’s not documented in that module. It’s only available if you’re using a SQL based adapter.

LostKobrakai

LostKobrakai

I don’t know what exactly happens behind the scenes, but I doubt the db does actually interpolate values:

Repo.explain(:all, query)

Last Post!

waseigo

waseigo

Thanks for sharing, very useful!

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New

We're in Beta

About us Mission Statement