# diesel-rs/diesel

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/diesel-rs-diesel).**

14,021 stars · 1,183 forks · Rust · apache-2.0

## Links

- GitHub: https://github.com/diesel-rs/diesel
- Homepage: https://diesel.rs
- awesome-repositories: https://awesome-repositories.com/repository/diesel-rs-diesel.md

## Topics

`mysql` `orm` `postgresql` `query-builder` `rust` `sqlite`

## Description

This project is a type-safe database toolkit and object-relational mapper designed to enforce structural consistency between database schemas and application code. By leveraging compile-time validation, it ensures that SQL queries and data structures remain synchronized, preventing common errors before the application executes. It provides a comprehensive framework for relational data modeling, allowing developers to define table associations and map database results directly into strongly-typed language objects.

The library distinguishes itself through its focus on compile-time safety and automated schema management. It utilizes procedural macros to inspect database tables and generate corresponding code structures, eliminating the need for manual type definitions. Its expression-based query builder allows for the construction of complex, modular SQL statements that are automatically parameterized to mitigate security risks like SQL injection. Furthermore, the system supports extensive customization, enabling developers to register custom functions and operators or extend the query builder interface to accommodate specific database requirements.

Beyond its core mapping and validation capabilities, the toolkit provides a full suite of operations for managing data persistence. This includes support for batch insertions, relational joins, upsert operations, and the retrieval of related records. The library also handles the bidirectional transformation of data, automatically mapping application structures to database columns for updates and insertions while inferring return types for query results.

Comprehensive documentation and tooling are provided to assist with schema synchronization, ensuring that local code representations remain aligned with the underlying database throughout the development lifecycle.

## Tags

### Data & Databases

- [Object-Relational Mappers](https://awesome-repositories.com/f/data-databases/object-relational-mappers.md) — Maps relational database results into strongly-typed objects and manages complex table associations.
- [Type-Safe Query Builders](https://awesome-repositories.com/f/data-databases/type-safe-query-builders.md) — Provides a type-safe database interaction layer that validates queries at compile time.
- [Database ORMs](https://awesome-repositories.com/f/data-databases/database-orms.md) — Acts as a type-safe database abstraction layer that ensures structural alignment between schemas and application models.
- [Database Query Builders](https://awesome-repositories.com/f/data-databases/database-query-builders.md) — Constructs SQL statements using a fluent, expression-based interface for secure and efficient database commands.
- [Row-to-Struct Mappers](https://awesome-repositories.com/f/data-databases/data-mapping/struct-hydrators/row-to-struct-mappers.md) — Automatically maps database result rows to strongly-typed application objects.
- [Database Schema Migrations](https://awesome-repositories.com/f/data-databases/database-management-systems/database-systems-management/database-management/database-schema-migrations.md) — Maintains local code representations by automatically updating definitions when migrations are applied. ([source](https://diesel.rs/guides/getting-started))
- [Database Schema Definitions](https://awesome-repositories.com/f/data-databases/database-schema-definitions.md) — Generates type-safe representations of database tables to keep application code synchronized with the schema. ([source](https://diesel.rs/guides/))
- [Relational Data Modeling](https://awesome-repositories.com/f/data-databases/relational-data-modeling.md) — Provides a framework for defining table associations and mapping relational data to application structures.
- [Table-to-Code Mappers](https://awesome-repositories.com/f/data-databases/table-definitions/object-mappings/table-to-code-mappers.md) — Defines type-safe structures for database tables to ensure compile-time query validation. ([source](https://diesel.rs/guides/schema-in-depth/))
- [Database Query Execution](https://awesome-repositories.com/f/data-databases/database-query-execution.md) — Executes constructed queries and maps results into native language structures. ([source](https://diesel.rs/guides/all-about-selects/))
- [Database Relationship Mappings](https://awesome-repositories.com/f/data-databases/database-relationship-mappings.md) — Declares parent-child relationships between data models to enable automated foreign key mapping. ([source](https://diesel.rs/guides/relations/))
- [Result Converters](https://awesome-repositories.com/f/data-databases/query-result-fetching/result-converters.md) — Converts query results into typed data structures by matching database columns to object fields. ([source](https://diesel.rs/guides/all-about-selects/))
- [Changeset Generators](https://awesome-repositories.com/f/data-databases/type-mapping-frameworks/script-to-native-type-mappings/entity-mappings/changeset-generators.md) — Automatically generates update statements from data structures while handling optional values. ([source](https://diesel.rs/guides/all-about-updates/))
- [Struct-to-Row Mappers](https://awesome-repositories.com/f/data-databases/type-mapping-frameworks/script-to-native-type-mappings/entity-mappings/struct-to-row-mappers.md) — Enables type-safe insertion of records by mapping application structures to database columns. ([source](https://diesel.rs/guides/all-about-inserts/))
- [Batch Insertion Interfaces](https://awesome-repositories.com/f/data-databases/data-insertion-interfaces/batch-insertion-interfaces.md) — Supports efficient batch insertion of multiple records to reduce query overhead. ([source](https://diesel.rs/guides/all-about-inserts/))
- [Data Type Mappings](https://awesome-repositories.com/f/data-databases/data-type-mappings.md) — Defines column structures that enforce SQL type safety during query building and data conversion. ([source](https://diesel.rs/guides/schema-in-depth.html))
- [Query Scopes](https://awesome-repositories.com/f/data-databases/database-query-builders/query-scopes.md) — Encapsulates common filtering and expression logic into reusable query components. ([source](https://diesel.rs/guides/composing-applications/))
- [Database Query Joins](https://awesome-repositories.com/f/data-databases/database-query-joins.md) — Constructs inner or left join queries to combine related data into single result sets. ([source](https://diesel.rs/guides/relations/))
- [Query Builders](https://awesome-repositories.com/f/data-databases/query-builders.md) — Extends the query builder DSL to support complex SQL patterns and custom operations. ([source](https://diesel.rs/guides/extending-diesel/))
- [Record Updating](https://awesome-repositories.com/f/data-databases/record-updating.md) — Enables type-safe modification of database rows using fluent query construction methods. ([source](https://diesel.rs/guides/all-about-updates/))
- [Upsert Strategies](https://awesome-repositories.com/f/data-databases/upsert-strategies.md) — Handles record conflicts during write operations to ensure data consistency. ([source](https://diesel.rs/guides/all-about-inserts/))
- [Model Persistence](https://awesome-repositories.com/f/data-databases/model-persistence.md) — Saves the state of identified records directly to the database by synchronizing fields with table rows. ([source](https://diesel.rs/guides/all-about-updates/))
- [Inserted Record Retrievers](https://awesome-repositories.com/f/data-databases/record-insertion/inserted-record-retrievers.md) — Returns values of newly created rows or specific columns immediately after an insertion operation. ([source](https://diesel.rs/guides/all-about-inserts/))
- [Single Record Retrievers](https://awesome-repositories.com/f/data-databases/single-record-retrievers.md) — Retrieves child records for parents using efficient batching to prevent performance-degrading query patterns. ([source](https://diesel.rs/guides/relations/))

### Development Tools & Productivity

- [Database Schema](https://awesome-repositories.com/f/development-tools-productivity/type-generators/database-schema.md) — Automatically derives type-safe code definitions from database schemas to ensure structural consistency.
- [Custom SQL Function Registrars](https://awesome-repositories.com/f/development-tools-productivity/custom-task-functions/sql-function-namespaces/custom-sql-function-registrars.md) — Allows registration of custom SQL functions with defined signatures for use in queries. ([source](https://diesel.rs/guides/extending-diesel/))
- [Custom SQL Operator Registrars](https://awesome-repositories.com/f/development-tools-productivity/developer-utilities-libraries/extensibility-frameworks/custom-operator-interfaces/custom-sql-operator-registrars.md) — Supports registration of custom SQL operators to extend query builder capabilities. ([source](https://diesel.rs/guides/extending-diesel/))

### Programming Languages & Runtimes

- [Database Schema Validators](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-safety/compile-time-type-generation/database-schema-validators.md) — Ensures SQL queries and data structures remain synchronized through compile-time validation.
- [Query Composition](https://awesome-repositories.com/f/programming-languages-runtimes/programming-language-varieties/programming-languages/type-systems/trait-based-polymorphism/traits/query-composition.md) — Enables modular and reusable SQL query construction through trait-based composition.

### Security & Cryptography

- [SQL Injection Prevention](https://awesome-repositories.com/f/security-cryptography/sql-injection-prevention.md) — Provides automated parameter binding for all database queries to prevent SQL injection vulnerabilities.
- [Database Injection Prevention](https://awesome-repositories.com/f/security-cryptography/application-and-system-security/web-security/input-sanitization/database-injection-prevention.md) — Uses automated parameterization for all inputs to prevent SQL injection vulnerabilities. ([source](https://diesel.rs/guides/all-about-selects/))

### Software Engineering & Architecture

- [Procedural Macro Generators](https://awesome-repositories.com/f/software-engineering-architecture/schema-generators/procedural-macro-generators.md) — Uses procedural macros to automatically generate type-safe structures from database tables.
- [Database Function Inference](https://awesome-repositories.com/f/software-engineering-architecture/type-safe-data-handling/type-inference-engines/database-function-inference.md) — Automatically infers return types for database expressions to simplify data retrieval. ([source](https://diesel.rs/guides/composing-applications/))
