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
Alias format for different table aliases.
alias_translator
Translate a canonical table alias into another AliasFormat format.
backend
Toql Api implementations that are database independend
cache
Cache to lookup static table information and SQL statements.
deserialize
Deserialize Error
error
Error handling.
field_handler
A FieldHandler may modify a mapped column or expression.
fields
A list of field names.
from_row
Trait to convert result row into structs.
identity
Identity trait.
join
Join enum to simplify update handling of joins.
join_handler
A JoinHandler may modify an ON condition in a join clause.
key
Table mapping information for keys.
key_fields
Toql query field information for keys.
keyed
Traits to access and change the key of a Toql derived struct.
map_key
An iterator that maps entities into keys.
mock_db
The Toql Mock Db provides a dummy database that can be used for testing or documentation examples.
page
Page is used as an argument in load functions.
page_counts
Return type of load_page method.
parameter_map
Combines multiple aux parameters in a lightweight way.
paths
A list of path names.
predicate_handler
A PredicateHandler may modify a mapped column or expression.
prelude
query
The Query represents a Toql query but also comes with query builder methods.
query_fields
Trait to associate a field type provider with a struct.
query_parser
The query parser can turn a string that follows the Toql query syntax into a Query.
query_path
Trait to associate a field type provider with a struct.
result
A result with a ToqlError.
role_expr
A boolean role expression that can be evaluated.
role_validator
Validate a RoleExpr.
sql
A raw SQL statement.
sql_arg
An argument for SQL expressions.
sql_builder
The SQL builder can build different select statements.
sql_expr
SQL expression than can be resolved into raw SQL.
table_mapper
Translate Toql query fields to database columns, SQL expressions, joins and merges.
table_mapper_registry
A registry for all table mappers.
toql_api
The common interface for all database backends.
tree
Traits to do operations on nested structs.

Macros§

join
log_literal_sql
log_sql
none_error
ok_or_fail
row
row macro for easier row creation