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
```rust use db_helpers::{Table,Q};
//index is optional //TABLE key is automatically replaced with table_name
struct User { //if name is not specified lowercase fieldname is used by default //q is mandatory #[table(name = "id", q = "bigserial primary key not null")] _id: i64, //name of this field is assumed username #[table( q = "text")] username: String, }
//index is optional
struct Op{
id:i64,
userid:i64,
}
rust
db.batchexecure(
//Available if pg feature is enabled
[User::pgcreatetablestr(),User::pgindex()].join(";")
).await;
//unfortunately for the time being <struct>::{
part cannot contain spaces smarter parsing is in the todo list
let User:User = db.queryone(Q!("select User::{id,username} from User::TABLE"),params!()).await.unwrap();
db.execute(Q!("insert into ( Foo::{username} ) VALUES ($1)"),params!("superman")).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.queryone(Q!("select User::{id,>username} from User::TABLE"),params!()).await.unwrap();
let ops : Vec
Please check changelog for details
TODO:
- [ ] allow using format macro inside Q
- [ ] 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