Struct PostgresBuilder

Source
pub struct PostgresBuilder {}
Expand description

examples

use sqlink::{
    PostgresBuilder,
    postgres::{format_query, op}
};
struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>
}

struct PersonForm {
    id: i32,
    name: String,
    data: Option<Vec<u8>>
}
// let mut conn = Client::connect("postgresql://pguser:password@localhost:54321/sqlink_postgres", NoTls).unwrap();
let person_form = PersonForm {
    id: 3,
    name: "Hello World".to_owned(),
    data: None
};
let mut sqlinsert = PostgresBuilder::insert();
let qbuiltinsert = sqlinsert
    .table("person")
    .returning("id")
    .set("id", &person_form.id)
    .set("name", &person_form.name)
    .set("data", &person_form.data)
    .build().unwrap();
// let mut id: i32 = 0;
// for row in &conn.query(
//     qbuiltinsert.query.as_str(),
//     &qbuiltinsert.parameters,
// )? {
//     id = row.get(0);
// }
// assert_eq!(id, 3);
let mut sqlupdate = PostgresBuilder::update();
let qbuiltinsert = sqlupdate
    .table("person")
    .set("name", &("Real Hello World"))
    .and_where(
        op::eq("person.id", &3) // equivalence to format_query("person.id = {}", vec![&3]), note that 3 has to be same type as person id, which is i32/INT here
    )
    .build().unwrap();
let mut sqlselect = PostgresBuilder::select();
let qbuiltselect = sqlselect
    .select("id")
    .select_as("name", "person_name")
    .select("data")
    .table("person")
    .and_where(
        format_query("person.id = {}", vec![&3])
    )
    .limit_offset(10) // equivalent of limit_offset((10, 0)), which is limit 10 offset 0
    .order("id", "ASC")
    .build().unwrap();
// misc feature
sqlselect
    .reset_selects()
    .select("COUNT(id)")
    .group("something")
    .build().unwrap();

let mut sqldelete = PostgresBuilder::delete();
let qbuiltdelete = sqldelete
    .table("person")
    .and_where(
        op::eq("person.id", &3)
    )
    .build().unwrap();

Implementations§

Source§

impl PostgresBuilder

Source

pub fn insert() -> SqlInsert<'static>

Source

pub fn select() -> SqlSelect<'static>

Source

pub fn update() -> SqlUpdate<'static>

Source

pub fn delete() -> SqlDelete<'static>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V