pub trait GeekConnector<'a, C>where
C: GeekConnection<Connection = C> + 'a,
Self: Sized + TableBuilder + QueryBuilderTrait + Serialize + DeserializeOwned,{
Show 20 methods
// Required methods
async fn save(&mut self, connection: &'a C) -> Result<(), Error>;
async fn fetch(&mut self, connection: &'a C) -> Result<(), Error>;
async fn fetch_or_create(&mut self, connection: &'a C) -> Result<(), Error>;
async fn search(
connection: &'a C,
search: impl Into<String>,
) -> Result<Vec<Self>, Error>;
// Provided methods
async fn query(connection: &'a C, query: Query) -> Result<Vec<Self>, Error> { ... }
async fn query_first(connection: &'a C, query: Query) -> Result<Self, Error> { ... }
async fn execute(connection: &'a C, query: Query) -> Result<(), Error> { ... }
async fn create_table(connection: &'a C) -> Result<(), Error> { ... }
async fn row_count(connection: &'a C, query: Query) -> Result<i64, Error> { ... }
async fn total(connection: &'a C) -> Result<i64, Error> { ... }
async fn all(connection: &'a C) -> Result<Vec<Self>, Error> { ... }
async fn page(connection: &'a C, page: &Page) -> Result<Vec<Self>, Error> { ... }
async fn paginate(connection: &'a C) -> Result<Pagination<Self>, Error> { ... }
async fn update(&mut self, connection: &'a C) -> Result<(), Error> { ... }
async fn delete(&self, connection: &'a C) -> Result<(), Error> { ... }
async fn filter(
connection: &'a C,
fields: Vec<(&str, impl Into<Value>)>,
) -> Result<Vec<Self>, Error> { ... }
async fn filter_page(
connection: &'a C,
fields: Vec<(&str, impl Into<Value>)>,
page: &Page,
) -> Result<Vec<Self>, Error> { ... }
async fn fetch_all(connection: &'a C) -> Result<Vec<Self>, Error> { ... }
async fn first(connection: &'a C) -> Result<Self, Error>
where Self: TablePrimaryKey { ... }
async fn last(connection: &'a C) -> Result<Self, Error>
where Self: TablePrimaryKey { ... }
}
Expand description
GeekConnection is the trait used for models to interact with the database.
This trait is used to define the methods that are used to interact with the database.
Required Methods§
Sourceasync fn save(&mut self, connection: &'a C) -> Result<(), Error>
async fn save(&mut self, connection: &'a C) -> Result<(), Error>
Save the current object to the database
Sourceasync fn fetch(&mut self, connection: &'a C) -> Result<(), Error>
async fn fetch(&mut self, connection: &'a C) -> Result<(), Error>
Fetches all of the foreign key values for the current object
Provided Methods§
Sourceasync fn query(connection: &'a C, query: Query) -> Result<Vec<Self>, Error>
async fn query(connection: &'a C, query: Query) -> Result<Vec<Self>, Error>
Query the database with an active Connection and Query
Sourceasync fn query_first(connection: &'a C, query: Query) -> Result<Self, Error>
async fn query_first(connection: &'a C, query: Query) -> Result<Self, Error>
Query the first row from the database with an active Connection and Query
Sourceasync fn execute(connection: &'a C, query: Query) -> Result<(), Error>
async fn execute(connection: &'a C, query: Query) -> Result<(), Error>
Execute a query on the database and do not return any rows
Sourceasync fn row_count(connection: &'a C, query: Query) -> Result<i64, Error>
async fn row_count(connection: &'a C, query: Query) -> Result<i64, Error>
Count the number of rows based on a Query
Sourceasync fn total(connection: &'a C) -> Result<i64, Error>
async fn total(connection: &'a C) -> Result<i64, Error>
Count the total number of rows in the table
Sourceasync fn paginate(connection: &'a C) -> Result<Pagination<Self>, Error>
async fn paginate(connection: &'a C) -> Result<Pagination<Self>, Error>
Create a new Pagination instance with the current table and fetch total number of rows
Sourceasync fn update(&mut self, connection: &'a C) -> Result<(), Error>
async fn update(&mut self, connection: &'a C) -> Result<(), Error>
Update the current object in the database
Sourceasync fn delete(&self, connection: &'a C) -> Result<(), Error>
async fn delete(&self, connection: &'a C) -> Result<(), Error>
Delete the current object from the database
Sourceasync fn filter(
connection: &'a C,
fields: Vec<(&str, impl Into<Value>)>,
) -> Result<Vec<Self>, Error>
async fn filter( connection: &'a C, fields: Vec<(&str, impl Into<Value>)>, ) -> Result<Vec<Self>, Error>
Filter the rows in the table based on specific criteria passed as a tuple of (&str, Value).
You can use prefix operators to define the type of comparison to use:
=
: Equal~
: Like!
: Not equal
If no prefix is used, the default comparison is equal.
Sourceasync fn filter_page(
connection: &'a C,
fields: Vec<(&str, impl Into<Value>)>,
page: &Page,
) -> Result<Vec<Self>, Error>
async fn filter_page( connection: &'a C, fields: Vec<(&str, impl Into<Value>)>, page: &Page, ) -> Result<Vec<Self>, Error>
Filter with Pagination
Sourceasync fn fetch_all(connection: &'a C) -> Result<Vec<Self>, Error>
👎Deprecated since 0.8.4: Please use the all
method instead of fetch_all
async fn fetch_all(connection: &'a C) -> Result<Vec<Self>, Error>
all
method instead of fetch_all
Fetch all rows from the database
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.