pub trait Connector {
// Required methods
fn try_new_data_source(config: &Table) -> Result<DataSource, Error>;
async fn execute(
&self,
query: &str,
params: Option<&Map>,
) -> Result<Option<u64>, Error>;
async fn query(
&self,
query: &str,
params: Option<&Map>,
) -> Result<Vec<Record>, Error>;
async fn query_one(
&self,
query: &str,
params: Option<&Map>,
) -> Result<Option<Record>, Error>;
// Provided methods
async fn query_as<T: DeserializeOwned>(
&self,
query: &str,
params: Option<&Map>,
) -> Result<Vec<T>, Error> { ... }
async fn query_one_as<T: DeserializeOwned>(
&self,
query: &str,
params: Option<&Map>,
) -> Result<Option<T>, Error> { ... }
}
Expand description
Underlying trait of all data sources for implementors.
Required Methods§
Sourcefn try_new_data_source(config: &Table) -> Result<DataSource, Error>
fn try_new_data_source(config: &Table) -> Result<DataSource, Error>
Constructs a new data source with the configuration, returning an error if it fails.
Sourceasync fn execute(
&self,
query: &str,
params: Option<&Map>,
) -> Result<Option<u64>, Error>
async fn execute( &self, query: &str, params: Option<&Map>, ) -> Result<Option<u64>, Error>
Executes the query and returns the total number of rows affected.
Provided Methods§
Sourceasync fn query_as<T: DeserializeOwned>(
&self,
query: &str,
params: Option<&Map>,
) -> Result<Vec<T>, Error>
async fn query_as<T: DeserializeOwned>( &self, query: &str, params: Option<&Map>, ) -> Result<Vec<T>, Error>
Executes the query and parses it as Vec<T>
.
Sourceasync fn query_one_as<T: DeserializeOwned>(
&self,
query: &str,
params: Option<&Map>,
) -> Result<Option<T>, Error>
async fn query_one_as<T: DeserializeOwned>( &self, query: &str, params: Option<&Map>, ) -> Result<Option<T>, Error>
Executes the query and parses it as an instance of type T
.
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.
Implementations on Foreign Types§
Source§impl Connector for MySqlPool
Available on crate feature connector-mysql
only.
impl Connector for MySqlPool
Available on crate feature
connector-mysql
only.fn try_new_data_source(config: &Table) -> Result<DataSource, Error>
async fn execute( &self, query: &str, params: Option<&Map>, ) -> Result<Option<u64>, Error>
async fn query( &self, query: &str, params: Option<&Map>, ) -> Result<Vec<Record>, Error>
async fn query_as<T: DeserializeOwned>( &self, query: &str, params: Option<&Map>, ) -> Result<Vec<T>, Error>
async fn query_one( &self, query: &str, params: Option<&Map>, ) -> Result<Option<Record>, Error>
async fn query_one_as<T: DeserializeOwned>( &self, query: &str, params: Option<&Map>, ) -> Result<Option<T>, Error>
Source§impl Connector for PgPool
Available on crate feature connector-postgres
only.
impl Connector for PgPool
Available on crate feature
connector-postgres
only.fn try_new_data_source(config: &Table) -> Result<DataSource, Error>
async fn execute( &self, query: &str, params: Option<&Map>, ) -> Result<Option<u64>, Error>
async fn query( &self, query: &str, params: Option<&Map>, ) -> Result<Vec<Record>, Error>
async fn query_as<T: DeserializeOwned>( &self, query: &str, params: Option<&Map>, ) -> Result<Vec<T>, Error>
async fn query_one( &self, query: &str, params: Option<&Map>, ) -> Result<Option<Record>, Error>
async fn query_one_as<T: DeserializeOwned>( &self, query: &str, params: Option<&Map>, ) -> Result<Option<T>, Error>
Source§impl Connector for SqlitePool
Available on crate feature connector-sqlite
only.
impl Connector for SqlitePool
Available on crate feature
connector-sqlite
only.fn try_new_data_source(config: &Table) -> Result<DataSource, Error>
async fn execute( &self, query: &str, params: Option<&Map>, ) -> Result<Option<u64>, Error>
async fn query( &self, query: &str, params: Option<&Map>, ) -> Result<Vec<Record>, Error>
async fn query_as<T: DeserializeOwned>( &self, query: &str, params: Option<&Map>, ) -> Result<Vec<T>, Error>
async fn query_one( &self, query: &str, params: Option<&Map>, ) -> Result<Option<Record>, Error>
async fn query_one_as<T: DeserializeOwned>( &self, query: &str, params: Option<&Map>, ) -> Result<Option<T>, Error>
Implementors§
impl Connector for ArrowConnector
Available on crate feature
connector-arrow
only.impl Connector for DataSource
impl Connector for HttpConnector
Available on crate feature
connector-http
only.