initial version

This commit is contained in:
2022-01-23 12:59:40 +01:00
commit 2de93bd470
4 changed files with 2348 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

2299
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "demo"
version = "0.1.0"
edition = "2021"
[dependencies]
actix-web = "3"
tokio = { version = "0.2", features = ["macros"] }
sqlx = { version = "0.4", features = ["runtime-actix-rustls", "postgres"] }

39
src/main.rs Normal file
View File

@ -0,0 +1,39 @@
use sqlx::postgres::{PgConnectOptions, PgPoolOptions};
use sqlx::{Acquire, PgPool, Postgres};
async fn take_pool_or_transaction<'c, C>(pool_or_transaction: C)
where
C: Acquire<'c, Database = Postgres>,
{
let mut connection = pool_or_transaction.acquire().await.unwrap();
sqlx::query("select 1 from dual")
.execute(&mut *connection)
.await
.unwrap();
}
async fn run(pool: PgPool) {
take_pool_or_transaction(&pool).await;
let mut t = pool.begin().await.unwrap();
take_pool_or_transaction(&mut *t).await;
}
#[actix_web::main]
async fn main() {
let options = PgConnectOptions::new();
let pool = PgPoolOptions::new().connect_lazy_with(options);
let clone = pool.clone();
//tokio::spawn(async move {
run(clone).await;
//});
sqlx::query("select 1 from dual")
.execute(&pool)
.await
.unwrap();
println!("Hello, world!");
}