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

Features

Usage

```rust use db_helpers::{Table,Q};

[derive(Table)]

//index is optional //TABLE key is automatically replaced with table_name

[table(name = "users", index = "create unique index if not exists uniqueusernamesof_users on TABLE (username)")]

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, }

[derive(Table)]

//index is optional

[table(name = "ops")]

struct Op{

[table(q="bigserial not null primary key")]

id:i64,

[table(q="bigint not null references")]

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 = db .query(Q!("select * from Op::TABLE where Op::{userid} = (select Foo::{id} from Foo::TABLE where Foo::{username} = $1)"), params!("superman")) .await.unwrap().iter(Into::into).collect(); ```

Error Messages

invalid<em>struct missing</em>fields no<em>field missing</em>close

How to upgrade from 0x releases

Please check changelog for details

TODO: