Crate derive_sql
source ·Expand description
The crate derive_sql is articulated around two traits.
The trait Sqlable that defines a set of operation for
interacting with SQL tables:
countto provide a count of the number of items in the table.selectto return an array of the items in the table.insertto insert a new item in the table.updateto update an existing item(s) with the values of the provided item.deleteto delete items in the table.delete_tableto drop the table.
Implementation of the trait should allow the user of the trait to interact with the table via the above interface…
The trait Selectable provides a possible interface for selector queries
used in the Sqlable trait. It is a possible option - but not limited
to it as the Sqlable trait uses an associated type for Selector.
This crate includes the derive macro DeriveSqlite [when compiled with the feature --features sqlite]
which provides an implementation of the Sqlable trait for SQLite as a wrapper around the rusqlite
crate.
Please see examples here and the DeriveSqlite documentation.
Features:
sqliteprovide a derive macro to implement theSqlabletrait for SQLite database (implemented as a wrapper around therusqlitecrate);with-mockprovide aMockSqlableimplementation of theSqlabletrait to use in testing.
Structs
- Convenient struct for implementing a simple filter, ie a struct that generates the content of a simple
WHERE a = valueclause - Convenient struct for implementing a limit, ie a struct that generates the content of a
LIMIT valueclause - Convenient struct for implementing am offset, ie a struct that generates the content of an
OFFSET valueclause
Traits
- Definition of trait
Selectable. This trait outputs filter, limit and offset statement. - Definition of
Sqlabletrait to be implemented to allow interaction with SQL tables.