sea-query

🔱 A dynamic SQL query builder for MySQL, Postgres and SQLite

What is sea-query?

🔱 A dynamic SQL query builder for MySQL, Postgres and SQLite

Overview of sea-query

What it is

SeaQuery is a dynamic SQL query builder for Rust that helps construct SQL queries as abstract syntax trees using an ergonomic API. It supports MySQL, Postgres, and SQLite behind a common interface. MS SQL Server support is available under SeaORM X. The library is written in 100% safe Rust, with all workspace crates forbidding unsafe code. SeaQuery is the foundation of SeaORM, an async and dynamic ORM for Rust. It provides integration for SQLx, postgres, and rusqlite.

Key features

  • Parameter bindings: inject parameters alongside expressions; the $N sequencing is handled automatically.
  • Dynamic query construction: build queries at runtime based on user inputs using a fluent interface, without conditional string concatenation.
  • Cross-database support: target multiple database backends (MySQL, Postgres, SQLite) while maintaining a single source of query logic.
  • Improved raw SQL ergonomics: the raw_query! macro supports named parameters, nested field access, array expansion, and tuple expansion.
  • Complex condition building: internal AST allows arbitrarily complex conditions with correct operator precedence.
  • Schema statement builders: support for CREATE, ALTER, DROP, RENAME, TRUNCATE tables, as well as foreign keys and indexes.

Use cases

  • Building dynamic SQL queries in Rust applications where the query structure depends on user input.
  • Avoiding manual parameter binding errors by using the library's automatic sequencing.
  • Writing database-agnostic code that can run against MySQL, Postgres, or SQLite without changing query logic.
  • Constructing complex SQL expressions and conditions with a type-safe API.
  • Generating SQL for schema migrations or database administration tasks.

Getting started

Add the following to your Cargo.toml:

[dependencies]
sea-query = "1.0"

SeaQuery is lightweight; all dependencies are optional. Feature flags are available for macros, SQL engines, and type support. See the repository README for a full list of feature flags and usage examples.

License and pricing

The license is not stated in the provided metadata. The project is listed as open source (pricing type: open_source). No pricing information is available.

Based on the project's public README and repository metadata.

Add this badge to your README

Featured on YunoDB Badge styles & help

Maintain this project? Show that it is featured on YunoDB.

Markdown[![Featured on YunoDB](https://yunodb.com/badge/seaqlsea-query.svg)](https://yunodb.com/tools/seaqlsea-query?utm_source=github&utm_medium=badge)
HTML<a href="https://yunodb.com/tools/seaqlsea-query?utm_source=github&utm_medium=badge"><img src="https://yunodb.com/badge/seaqlsea-query.svg" alt="Featured on YunoDB" height="20"></a>