Crate toql

source · []
Expand description

Toql - A friendly and productive ORM

Beginner Guide, API documentation

Toql is an ORM for async databases that features

  • Translation between Rust structs and database tables.
  • Can load and modify nested structs.
  • A unique dead simple query language, suitable for web clients.
  • Different table aliases from long and readable to tiny and fast.
  • Prepared statements against SQL injection.
  • Support for raw SQL for full database power.
  • Support for role based access.
  • Highly customizable through user defined parameters, query functions, field handlers, etc.
  • Compile time safety for queries, fields and path names.
  • No unsafe Rust code.
  • Tested on real world scenario.

It currently only supports MySQL. More are coming, promised :)

Installation

Add this to your Cargo.toml:

[dependencies]
toql = {version = "0.3", features = ["serde"]}
toql_mysql_async = "0.3"

Look And Feel

Derive your structs:

#[derive(Toql)]
#[toql(auto_key = true)]
struct Todo {
    #[toql(key)]
    id: u64,
    what: String,

    #[toql(join())]
    user: User
}

And do stuff with them:

let toql = ...
let todo = Todo{ ... };

// Insert todo and update its generated id
toql.insert_one(&mut todo, paths!(top)).await?;

// Compile time checked queries!
let q = query!(Todo, "*, user_id eq ?", &todo.user.id);

// Typesafe loading
let user = toql.load_many(q).await?;

Quick start

Toql has a supporting crate to play well with Rocket. Check out the CRUD example.

Contribution

Comments, bug fixes and quality improvements are welcome.

License

Toql is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

Re-exports

pub use toql_derive as derive;
pub use toql_fields_macro as fields_macro;
pub use toql_paths_macro as paths_macro;
pub use toql_query_macro as query_macro;
pub use toql_role_expr_macro as role_expr_macro;
pub use toql_sql_expr_macro as sql_expr_macro;
pub use toql_core::tracing;

Modules

Alias format for different table aliases.

Translate a canonical table alias into another AliasFormat format.

Toql Api implementations that are database independend

Cache to lookup static table information and SQL statements.

Deserialize Error

Error handling.

A FieldHandler may modify a mapped column or expression.

A list of field names.

Trait to convert result row into structs.

Identity trait.

Join enum to simplify update handling of joins.

A JoinHandler may modify an ON condition in a join clause.

Table mapping information for keys.

Toql query field information for keys.

Traits to access and change the key of a Toql derived struct.

An iterator that maps entities into keys.

The Toql Mock Db provides a dummy database that can be used for testing or documentation examples.

Page is used as an argument in load functions.

Return type of load_page method.

Combines multiple aux parameters in a lightweight way.

A list of path names.

A PredicateHandler may modify a mapped column or expression.

The Query represents a Toql query but also comes with query builder methods.

Trait to associate a field type provider with a struct.

The query parser can turn a string that follows the Toql query syntax into a Query.

Trait to associate a field type provider with a struct.

A result with a ToqlError.

A boolean role expression that can be evaluated.

A raw SQL statement.

An argument for SQL expressions.

The SQL builder can build different select statements.

SQL expression than can be resolved into raw SQL.

Translate Toql query fields to database columns, SQL expressions, joins and merges.

A registry for all table mappers.

The common interface for all database backends.

Traits to do operations on nested structs.

Macros

row macro for easier row creation