sqlink 0.2.0

postgres builder to work with postgres

Postgres Query Builder for Rust

  • for usage with postgres crate

For How it works

extern crate postgres;
use postgres::{Connection, TlsMode, Error as PostgresError};
use sqlink::postgres::{SqlInsert, SqlSelect};
use sqlink_derive::{postgres_fmt};
#[derive(Debug, PartialEq)]
struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>

struct PersonForm {
    id: i32,
    name: String,
    data: Option<Vec<u8>>

fn test_postgres_db() -> Result<(), PostgresError> {
    let conn = Connection::connect("postgresql://pguser:password@localhost:54321/sqlink_postgres", TlsMode::None)
    conn.execute("DROP TABLE IF EXISTS person", &[]).unwrap();
    conn.execute("CREATE TABLE person (
        id              INT PRIMARY KEY,
        name            VARCHAR(255) NOT NULL,
        data            Bytea
      )", &[]).unwrap();

    let person_form = PersonForm {
        id: 3,
        name: "Hello World".to_owned(),
        data: None
    let mut sqlinsert = SqlInsert::new();
    let qbuild = sqlinsert
        .into(("id", person_form.id))
        .into(("name", person_form.name))
        .into(("data", person_form.data))
    let mut sqlselect = SqlSelect::new();
    let qbuild2 = sqlselect
        .select(("name", "person_name"))
            postgres_fmt!("person.id = {}", 3) // note that 3 has to be same type as person id, which is i32/INT here
    let mut person_vec: Vec<Person> = Vec::new();
    for row in &conn.query(&qbuild2.query, &qbuild2.parameters).unwrap() {
        person_vec.push(Person {
            id: row.get(0),
            name: row.get(1),
            data: row.get(2),
    assert_eq!(person_vec, vec![Person {
        id: 3,
        name: "Hello World".to_owned(),
        data: None


Current queryfmt macro does not intelligently notify error like how format! macro do