Installation and Configuration
Relevant source files
The following files were used as context for generating this wiki page:
SeaQuery is a dynamic SQL query builder for Rust, designed to be lightweight with a modular architecture where nearly all dependencies are optional. It provides a common interface for MySQL, Postgres, and SQLite, allowing developers to build complex abstract syntax trees (AST) for expressions, queries, and schemas.
The installation process involves adding the core crate to your project and enabling specific feature flags based on the required database backends, data types, and integration drivers. SeaQuery serves as the foundation for SeaORM but can be used independently or with common database drivers like SQLx, Diesel, and Rusqlite.
Sources: README.md:15-32, src/lib.rs:31-48
Core Installation
To include SeaQuery in a Rust project, add the dependency to the Cargo.toml file. The library requires a minimum Rust version (MSRV) of 1.88.0.
[dependencies]
sea-query = "1.0"
Sources: README.md:36-39, Cargo.toml:15
Feature Flag Architecture
SeaQuery uses a comprehensive set of feature flags to manage its capabilities. This allows for a minimal binary size by only including the logic necessary for specific use cases.
The diagram above illustrates how SeaQuery categorizes its optional functionalities through feature flags.
Sources: README.md:43-52, Cargo.toml:57-110
Configuration Options
Database Backends
By default, SeaQuery supports three major database engines. These must be enabled to use the corresponding query builders (e.g., PostgresQueryBuilder).
| Feature Flag | Description |
|---|---|
backend-mysql | Enables MySQL query generation and syntax. |
backend-postgres | Enables Postgres query generation and specific types. |
backend-sqlite | Enables SQLite query generation. |
Sources: README.md:47, Cargo.toml:59-61
Data Type Support
To use specialized Rust types within queries, the following flags are available:
| Category | Feature Flag | Integration |
|---|---|---|
| Time/Date | with-chrono, with-time, with-jiff | Chrono, Time, or Jiff crates |
| Numeric | with-rust_decimal, with-bigdecimal | Decimal and arbitrary precision types |
| Network | with-ipnetwork, with-mac_address | IP and MAC address support |
| Specialized | with-uuid, with-json | UUID and Serde JSON support |
| Postgres | postgres-array, postgres-vector, postgres-interval | Postgres-specific complex types |
Sources: README.md:49-52, Cargo.toml:92-108
Driver Integrations
SeaQuery provides specialized adapter crates for binding queries to popular Rust database drivers. These are typically installed as separate dependencies alongside the main crate.
SQLx Integration
The sea-query-sqlx crate facilitates using SeaQuery with the SQLx ecosystem. It includes features for various runtimes and TLS backends.
- Backends:
sqlx-mysql,sqlx-postgres,sqlx-sqlite,sqlx-any - Runtimes:
runtime-async-std,runtime-tokio,runtime-actix - TLS:
tls-native-tls,tls-rustls
Sources: sea-query-sqlx/Cargo.toml:23-45
Diesel Integration
The sea-query-diesel crate provides binder traits for Diesel.
[dependencies]
sea-query-diesel = { version = "0.3", features = ["postgres", "with-chrono"] }
Sources: sea-query-diesel/Cargo.toml:1-48
Driver Support Matrix
| Driver | Crate Name | Key Features |
|---|---|---|
| SQLx | sea-query-sqlx | Support for async runtimes and sqlx-any |
| Diesel | sea-query-diesel | Trait-based binders for Diesel 2.x |
| Rusqlite | sea-query-rusqlite | Synchronous SQLite bindings |
| Postgres | sea-query-postgres | Native rust-postgres driver support |
| Rbatis | sea-query-rbatis | Support for the Rbatis ORM |
Sources: sea-query-sqlx/Cargo.toml, sea-query-diesel/Cargo.toml, sea-query-rusqlite/Cargo.toml, sea-query-postgres/Cargo.toml, sea-query-rbatis/Cargo.toml
Summary
Installing SeaQuery requires selecting the appropriate feature flags for your target database (MySQL, Postgres, or SQLite) and any non-standard Rust types you intend to use. For execution, developers should choose an integration crate like sea-query-sqlx or sea-query-diesel to bridge the gap between query construction and database communication.
Sources: README.md:15-52, src/lib.rs:31-70