pub trait TransactionOps {
// Required methods
fn insert<'life0, 'async_trait, T>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where T: SqlQuery + SqlParams + Debug + Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn update<'life0, 'async_trait, T>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where T: SqlQuery + UpdateParams + SqlParams + Debug + Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn delete<'life0, 'async_trait, T>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where T: SqlQuery + SqlParams + Debug + Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
params: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'async_trait>>
where T: SqlQuery + FromRow + SqlParams + Debug + Send + Sync + Clone + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get_all<'life0, 'life1, 'async_trait, T>(
&'life0 self,
params: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, Error>> + Send + 'async_trait>>
where T: SqlQuery + FromRow + SqlParams + Debug + Send + Sync + Clone + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn select<'life0, 'async_trait, T, R, F>(
&'life0 self,
entity: T,
to_model: F,
) -> Pin<Box<dyn Future<Output = Result<R, Error>> + Send + 'async_trait>>
where T: SqlQuery + SqlParams + Debug + Send + 'static + 'async_trait,
F: FnOnce(&Row) -> Result<R, Error> + Send + Sync + 'static + 'async_trait,
R: Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn select_all<'life0, 'async_trait, T, R, F>(
&'life0 self,
entity: T,
to_model: F,
) -> Pin<Box<dyn Future<Output = Result<Vec<R>, Error>> + Send + 'async_trait>>
where T: SqlQuery + SqlParams + Debug + Send + 'static + 'async_trait,
F: Fn(&Row) -> R + Send + Sync + 'static + 'async_trait,
R: Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
TransactionOps trait, Transaction için CRUD işlemlerini extension method olarak sağlar Bu şekilde, herhangi bir Transaction nesnesi üzerinde doğrudan CRUD işlemleri yapılabilir
Required Methods§
Sourcefn insert<'life0, 'async_trait, T>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
fn insert<'life0, 'async_trait, T>( &'life0 self, entity: T, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
Insert method, yeni bir kayıt eklemek için kullanılır
§Parameters
entity
- Eklenecek varlık, SqlQuery ve SqlParams trait’lerini implement etmeli
§Örnek Kullanım
use deadpool_postgres::{Config, Runtime};
use parsql_deadpool_postgres::TransactionOps;
use tokio_postgres::NoTls;
// Entity tanımı
#[derive(SqlQuery, SqlParams)]
#[table("users")]
pub struct InsertUser {
pub name: String,
pub email: String,
}
#[tokio::main]
async fn main() -> Result<(), tokio_postgres::Error> {
let mut cfg = Config::new();
cfg.dbname = Some("test".to_string());
let pool = cfg.create_pool(Some(Runtime::Tokio1), NoTls).unwrap();
let client = pool.get().await?;
let tx = client.transaction().await?;
let user = InsertUser {
name: "John".to_string(),
email: "john@example.com".to_string(),
};
// Extension method kullanımı
let rows_affected = tx.insert(user).await?;
tx.commit().await?;
println!("{} kayıt eklendi", rows_affected);
Ok(())
}
Sourcefn update<'life0, 'async_trait, T>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
T: SqlQuery + UpdateParams + SqlParams + Debug + Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
fn update<'life0, 'async_trait, T>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
T: SqlQuery + UpdateParams + SqlParams + Debug + Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
Update method, mevcut bir kaydı güncellemek için kullanılır
§Parameters
entity
- Güncellenecek varlık, SqlQuery, UpdateParams ve SqlParams trait’lerini implement etmeli
Sourcefn delete<'life0, 'async_trait, T>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
fn delete<'life0, 'async_trait, T>( &'life0 self, entity: T, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
Delete method, bir kaydı silmek için kullanılır
§Parameters
entity
- Silinecek varlık, SqlQuery ve SqlParams trait’lerini implement etmeli
Sourcefn get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
params: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'async_trait>>
fn get<'life0, 'life1, 'async_trait, T>( &'life0 self, params: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'async_trait>>
Get method, tek bir kayıt getirmek için kullanılır
§Parameters
params
- Sorgu parametreleri, SqlQuery, FromRow ve SqlParams trait’lerini implement etmeli
Sourcefn get_all<'life0, 'life1, 'async_trait, T>(
&'life0 self,
params: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, Error>> + Send + 'async_trait>>
fn get_all<'life0, 'life1, 'async_trait, T>( &'life0 self, params: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>, Error>> + Send + 'async_trait>>
Get All method, birden fazla kayıt getirmek için kullanılır
§Parameters
params
- Sorgu parametreleri, SqlQuery, FromRow ve SqlParams trait’lerini implement etmeli
Sourcefn select<'life0, 'async_trait, T, R, F>(
&'life0 self,
entity: T,
to_model: F,
) -> Pin<Box<dyn Future<Output = Result<R, Error>> + Send + 'async_trait>>
fn select<'life0, 'async_trait, T, R, F>( &'life0 self, entity: T, to_model: F, ) -> Pin<Box<dyn Future<Output = Result<R, Error>> + Send + 'async_trait>>
Select method, özel dönüşüm fonksiyonu ile tek bir kayıt getirmek için kullanılır
§Parameters
entity
- Sorgu parametreleri, SqlQuery ve SqlParams trait’lerini implement etmelito_model
- Satırı istenen türe dönüştüren fonksiyon
Sourcefn select_all<'life0, 'async_trait, T, R, F>(
&'life0 self,
entity: T,
to_model: F,
) -> Pin<Box<dyn Future<Output = Result<Vec<R>, Error>> + Send + 'async_trait>>
fn select_all<'life0, 'async_trait, T, R, F>( &'life0 self, entity: T, to_model: F, ) -> Pin<Box<dyn Future<Output = Result<Vec<R>, Error>> + Send + 'async_trait>>
Select All method, özel dönüşüm fonksiyonu ile birden fazla kayıt getirmek için kullanılır
§Parameters
entity
- Sorgu parametreleri, SqlQuery ve SqlParams trait’lerini implement etmelito_model
- Her satırı istenen türe dönüştüren fonksiyon
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.