db_helpers
db_helpers provide various helpers to simplify and make safer to interact with databases.
This is not an orm library the idea is simply to be able to replace inline queries and start getting benefits without learning a new library
Why did I create db_helpers
- compile time checked field names in queries to make regular sql little bit more secure.
- To reduce boilerplate ( creating From for every struct namely)
Features
- Create table creation and indexing queries.(feature flag)
- Reduce boilerplate by implementing certain default such as row to struct conversion(feature flag)
- Compile time field name validation
- Meaningful error messages
Usage
use ;
//index is optional
//__TABLE__ key is automatically replaced with table_name
//index is optional
db.batch_execure.await;
//unfortunately for the time being `<struct>::{` part cannot contain spaces smarter parsing is in the todo list
let User:User = db.query_one.await.unwrap;
db.execute.await.unwrap;
//you can also use tablename.fieldname format using > in the beginning of the field
//produces `select id , users.username from users`
let User:User = db.query_one.await.unwrap;
let ops : = db
.query
.await.unwrap.iter.collect;
//it also supports runtime args using format macro
//if no additional arguments provided Q produces a &'static str otherwise it passes everything to format! macro
Q!
Error Messages
How to upgrade from 0x releases
Please check changelog for details
TODO:
- allow using format macro inside Q
- add support for raw string literals
- *- operator meaning all fields but the defined ones
Users::{*-password}
- infer postgres types from rust type where possible making
q
argument optional - parse
Q
smarter to allow using spaces in more places as well as no spaces in places like inserts - Sqlite backend