[−][src]Module toql_core::sql_mapper
The SQL Mapper translates Toql fields into database columns or SQL expressions.
It's needed by the SQL Builder to turn a Query into a SQL Builder Result. The result holds the different parts of an SQL query. It can be turned into SQL that can be sent to the database.
Example
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 with map(), the struct must implement the Mapped trait. The Toql derive implements that 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
Beside fields and joins the SQL Mapper also registers all filter operations. To add a custom operation you must define a new Fieldhandler and add it either
- to a single field with map_handler().
- to all fields with new_with_handler().
Caching
If a struct contains merged fields (collections of structs) then the SQL Builder must build multiple SQL queries with different mappers. To give high level functions all SQL Mappers, they must be put into a cache. This allows to load the full dependency tree.
Structs
BasicFieldHandler | Handles the standart filters as documented in the guide. Returns FilterInvalid for any attempt to use FN filters. |
MapperOptions | Options for a mapped field. |
SqlMapper | Translates Toql fields into columns or SQL expressions. |
Traits
FieldHandler | A FieldHandler maps a Toql field onto an SQL. Use it to |
Mapped | Structs that implement |
Functions
sql_param |
Type Definitions
SqlMapperCache | A cache that holds mappers. |