[][src]Module toql_core::sql_mapper

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

It's needed by the SQL Builder to turn a Query into a Sql Builder Result. The result hold the different parts of an SQL query and can be turned into SQL that can be sent to the database.

Example

This example is not tested
let mapper = SqlMapper::new("Bar b")
    .map_field("foo", "b.foo")
    .map_field("fuu_id", "u.foo")
    .map_field("faa", "(SELECT COUNT(*) FROM Faa WHERE Faa.bar_id = b.id)")
    .join("fuu", "LEFT JOIN Fuu u ON (b.foo_id = u.id)");

To map a full struct it's possible to implement the Mapped trait and call map. The Toql derive implements the trait for any derived struct.

Options

Field can have options. They can be hidden for example or require a certain role (permission). Use map_with_options.

Filter operations

Besides fields and joins the mapper also contains all filter operations. To add a custom operation you must define a new Fieldhandler and add it either

Caching

If a struct contains collections of other structs then the SQL Builder must create multiple SQL queries. To give high level functions all the mappers they must be put into a cache. This allows to load the whole dependency tree.

Structs

BasicFieldHandler

Handles the standart filters as documented in the guide. Throws an error upon all FN calls.

MapperOptions

Options for a mapped field.

SqlMapper

Maps from Toql fields onto columns or SQL expressions.

Traits

FieldHandler

A FieldHandler maps a Toql field onto an SQL. Use it to

Mapped

Structs that implement Mapped can be added to the mapper with map().

Functions

sql_param

Type Definitions

SqlMapperCache

A cache that holds mappers.