Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Elixir
  3. defql

defql

MITElixir

Create Elixir functions with SQL as the body for database operations.

GitHubGitHub
103 stars3 forks0 contributors

What is defql?

Defql is an Elixir library that enables developers to write database queries by defining functions where the body is SQL. It provides macros for common CRUD operations and raw SQL queries, simplifying database interactions in Elixir applications. It solves the problem of mixing SQL with Elixir code in a structured and maintainable way.

Target Audience

Elixir developers building applications that require direct SQL access or those looking for a lightweight alternative to full ORMs like Ecto's schema-based queries.

Value Proposition

Developers choose Defql for its straightforward approach to embedding SQL in Elixir, reducing boilerplate while keeping queries explicit and adaptable. It offers more control than abstracted ORMs without sacrificing Elixir's functional patterns.

Overview

Create elixir functions with SQL as a body.

Use Cases

Best For

  • Adding raw SQL queries to Elixir projects with minimal abstraction
  • Building lightweight data access layers without full ORM overhead
  • Migrating SQL-heavy applications to Elixir while preserving query logic
  • Creating reusable database modules with explicit SQL definitions
  • Integrating PostgreSQL with Elixir using standalone or Ecto adapters
  • Writing complex conditional queries with Elixir-style syntax

Not Ideal For

  • Projects requiring MySQL or multi-database support
  • Applications needing built-in transaction management for ACID compliance
  • Teams wanting full ORM features like associations, migrations, or schema validations
  • Systems where advanced error handling for database operations is critical

Pros & Cons

Pros

SQL as Function Body

Enables defining Elixir functions with raw SQL using `defquery`, keeping queries explicit and maintainable, as shown in the README examples for custom queries.

CRUD Macros Simplicity

Provides `defselect`, `definsert`, `defupdate`, and `defdelete` macros that reduce boilerplate for common operations, with optional table and column specifications.

Flexible Adapter Support

Works with both Ecto repositories and standalone PostgreSQL connections via configurable adapters, offering integration flexibility without locking into a single approach.

Elixir-Style Condition Syntax

Supports advanced SQL conditions like `:in`, `:like`, and `:ilike` directly in Elixir syntax, making query composition more intuitive, as listed in the README.

Cons

Limited Database Support

Primarily focused on PostgreSQL, with MySQL support listed as a TODO item, restricting use with other databases.

Missing Transaction Support

The TODO list includes adding transaction support, indicating it's not yet available, which could hinder data integrity in complex applications.

Incomplete Error Handling

The TODO mentions 'Support database errors,' suggesting that error management might be basic or unstable, potentially complicating debugging.

Potential Adapter Instability

The TODO includes 'Cleanup ECTO adapter,' implying possible integration issues or bugs when using Defql with Ecto.

Frequently Asked Questions

Quick Stats

Stars103
Forks3
Contributors0
Open Issues1
Last commit7 years ago
CreatedSince 2017

Tags

#query-builder#functional-programming#database#elixir#ecto#postgresql#orm-alternative#sql

Built With

E
Ecto
P
PostgreSQL
E
Elixir

Included in

Elixir13.1k
Auto-fetched 1 day ago

Related Projects

ectoecto

A toolkit for data mapping and language integrated query.

Stars6,467
Forks1,475
Last commit12 days ago
postgrexpostgrex

PostgreSQL driver for Elixir

Stars1,211
Forks302
Last commit26 days ago
eventstoreeventstore

Event store using PostgreSQL for persistence

Stars1,151
Forks155
Last commit1 month ago
redixredix

Fast, pipelined, resilient Redis driver for Elixir. 🛍

Stars1,136
Forks124
Last commit1 day ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub