siddhant3030
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw queries in phoenix. So to understand
I have created a user schema that inserts an email in a database table.
So created the changeset the like this
def changeset(user, attrs) do
user
|> cast(attrs, [:email, :password])
end
Now I have a create function that I’m using in my model. So the model will basically talk to db.
def create_user(attrs \\ %{}) do
%User{}
|> User.changeset(attrs)
|> Repo.insert()
end
I have inserted an email in my database. using this
iex(1) > user = User.changeset(%User{}, %{email: “”, password: “”})
Now what I want is to find that user by his email address.
Also If I wanted to fetch through id. I would just do this
def get_user!(id), do: Repo.get!(User, id)
But what if I want to write a raw query? How do I do that?
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
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
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
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
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
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
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
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
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
The best place to start is always the docs. Hint: it’s a function inside this module Ecto.Repo — Ecto v3.14.0
kokolegorille
You might also have a look at…
…for raw queries
benwilson512
Ah yeah, I’m realizing my post wasn’t super helpful because
, it’s just added inside repos that actually use SQL adapters. That’s unfortunate.
query!isn’t actually in the Repo docssiddhant3030
Thanks. This is helpful
al2o3cr
FWIW, you can do this with
Repo.get_by(User, email: email_to_find).lucaong
In case you are exercising raw SQL for learning, you can also directly use the
psqlcommand line client for Postgres (assuming that is your database of choice), and directly type SQL in the console.siddhant3030
Thanks
siddhant3030
Can anyone show me some project where sql raw
query is being used heavily. Not ecto queries
siddhant3030
Hi @kokolegorille
I’m confused about this. Because the database I’m querying is in postgres. But I want to write a raw sql query. Now phoenix comes with Postgres by default. So should I move my table to SQL Database in order to use raw queries ?
sribe
That makes no sense–if your table is not in a SQL database you can’t query with raw queries. I suspect you mean something else, but I can’t figure out what you’re asking…