pub trait TableHelper<T: 'static + Table>: Sync + Send {
// Required methods
fn delete_by_key<'life0, 'async_trait>(
&'life0 self,
key: Key<T>,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn insert<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn update<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn upsert<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn fetch_table<'life0, 'life1, 'async_trait>(
&'life0 self,
where_clause: WhereClause<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn bulk_insert<'life0, 'life1, 'async_trait>(
&'life0 self,
records: &'life1 [T],
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided method
fn delete<'life0, 'async_trait>(
&'life0 self,
record: T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}
Required Methods§
Sourcefn delete_by_key<'life0, 'async_trait>(
&'life0 self,
key: Key<T>,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete_by_key<'life0, 'async_trait>(
&'life0 self,
key: Key<T>,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Delete the record associated to the given key
fn insert<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn update<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn upsert<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn fetch_table<'life0, 'life1, 'async_trait>(
&'life0 self,
where_clause: WhereClause<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fetch_table<'life0, 'life1, 'async_trait>(
&'life0 self,
where_clause: WhereClause<'life1>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Fetch records of the given table with a specific WHERE
clause.
§Example
use inline_postgres as pg;
use pg::{key::Key, prelude::*, Table, sql};
fn main() -> Result<(), pg::Error> {
#[derive(Debug, Table)]
struct Celebrity {
id: Key<Self>,
first_name: String,
last_name: String,
}
let mut client = pg::Client::connect("host=localhost, user=postgres", pg::NoTls)?;
let client = &mut client;
client.insert(Celebrity::new("Tony", "Hawk"))?;
let people: Vec<Celebrity> = client.fetch_where(sql!{ FIRST_NAME = "Tony" })?;
assert_eq!(people.len(), 1);
assert_eq!(people[0].first_name, "Tony");
assert_eq!(people[0].last_name, "Hawk");
Ok(())
}