# Extend Ecto's query API with your own macros

> Here's a simple way to improve your workflow using custom Elixir macros. It's a simple trick that saves you keystrokes and time.

- URL: https://graffino.com/til/extend-ectos-query-api-with-your-own-macros
- Author: Nick Ciolpan
- Channel: elixir
- Published: 2020-07-07
- Updated: 2025-09-30

Imagine for a second this is something you're using a lot when programming Elixir and Phoenix: 

```                
Repo.one(
	from u in User,
		where: fragment("lower(?)", u.email) == ^email
)

```

You can write your own Elixir macro to improve your flow. 

```
defmacro lower(arg) do
	quote do: fragment("lower(?)", unquote(arg))
end
```

Then your query can be rewritten like this: 
```
Repo.one(
	from u in User,
		where: lower(u.email) == ^email
)

```
