[][src]Crate toql

Toql. Transfer Object Query Language

Welcome to Toql API documentation!

This API documentation is very technical and is purely a reference. There is a guide that is better to get started.

Overview

The project consists of the following main parts:

  • A Query Parser to build a Toql query from a string.
  • A Query that can be built with methods.
  • An SQL Mapper to map Toql fields to database columns or expressions.
  • An SQL Builder to turn your Toql query into an SQL statement using the mapper.
  • A Toql Derive to build all the boilerplate code to make some ✨ happen.
  • Integration with

Small Example

Using Toql without any dependency features is possible and easy. Here we go:

use toql::{query_parser::QueryParser, sql_mapper::SqlMapper, sql_builder::SqlBuilder};
 
let query = QueryParser::parse("id, +title LK '%foo%'").unwrap();
let mut mapper = SqlMapper::new("Book b");
    mapper
        .map_field("id", "b.id")
        .map_field("title", "b.title");

let result = SqlBuilder::new().build(&mapper, &query).unwrap();
assert_eq!("SELECT b.id, b.title FROM Book b WHERE b.title LIKE ? ORDER BY b.title ASC", result.to_sql());

Bigger Example

However using the Rocket and MySQL integration will reduce your amount of coding to a minimum. If you have a MySQL server running, check out the full CRUD example with:

ROCKET_DATABASES={example_db={url=mysql://USER:PASS@localhost:3306/example_db}} cargo +nightly run --example crud_rocket_mysql
 

Re-exports

pub use toql_derive as derive;
pub use log;

Modules

error

Error handling.

fields_type

Trait to associate a field type provider with a struct.

indelup

Insert / Delete / Update

merge

Generic merge function called by code from Toql derive. Used to merge a collection of structs into another collection of structs by equal keys

query

This module contains the query and all functions to build one programatically.

query_parser

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

sql_builder

The SQL Builder turns a Query with the help of a SQL Mapper into a Sql Builder Result The result hold the different parts of an SQL query and can be turned into an SQL query that can be sent to the database.

sql_builder_result

Result of SQL Builder. Use it to get SQL that can be sent to the database.

sql_mapper

The SQL Mapper translates Toql fields into databaae columns or SQL expressions.

Type Definitions

Result

A result with a ToqlError