Trait GeekConnector

Source
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§

Source

async fn save(&mut self, connection: &'a C) -> Result<(), Error>

Save the current object to the database

Source

async fn fetch(&mut self, connection: &'a C) -> Result<(), Error>

Fetches all of the foreign key values for the current object

Source

async fn fetch_or_create(&mut self, connection: &'a C) -> Result<(), Error>

Fetch or create a row in the database

Source

async fn search( connection: &'a C, search: impl Into<String>, ) -> Result<Vec<Self>, Error>

Search for a row in the database based on specific criteria

Provided Methods§

Source

async fn query(connection: &'a C, query: Query) -> Result<Vec<Self>, Error>

Query the database with an active Connection and Query

Source

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

Source

async fn execute(connection: &'a C, query: Query) -> Result<(), Error>

Execute a query on the database and do not return any rows

Source

async fn create_table(connection: &'a C) -> Result<(), Error>

Create a table in the database

Source

async fn row_count(connection: &'a C, query: Query) -> Result<i64, Error>

Count the number of rows based on a Query

Source

async fn total(connection: &'a C) -> Result<i64, Error>

Count the total number of rows in the table

Source

async fn all(connection: &'a C) -> Result<Vec<Self>, Error>

Fetch all rows from the table

Source

async fn page(connection: &'a C, page: &Page) -> Result<Vec<Self>, Error>

Fetch by Page

Source

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

Source

async fn update(&mut self, connection: &'a C) -> Result<(), Error>

Update the current object in the database

Source

async fn delete(&self, connection: &'a C) -> Result<(), Error>

Delete the current object from the database

Source

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.

Source

async fn filter_page( connection: &'a C, fields: Vec<(&str, impl Into<Value>)>, page: &Page, ) -> Result<Vec<Self>, Error>

Filter with Pagination

Source

async fn fetch_all(connection: &'a C) -> Result<Vec<Self>, Error>

👎Deprecated since 0.8.4: Please use the all method instead of fetch_all

Fetch all rows from the database

Source

async fn first(connection: &'a C) -> Result<Self, Error>
where Self: TablePrimaryKey,

Fetch the first row from the database (based on the primary key)

Source

async fn last(connection: &'a C) -> Result<Self, Error>
where Self: TablePrimaryKey,

Fetch last row from the database (based on the primary key)

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.

Implementors§