feat: add user in db
This commit is contained in:
@@ -0,0 +1 @@
|
||||
pub mod postgres;
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod pool;
|
||||
pub mod user_repository;
|
||||
@@ -0,0 +1,14 @@
|
||||
use sqlx::{PgPool, postgres::PgPoolOptions};
|
||||
use std::time::Duration;
|
||||
|
||||
pub async fn create_pool(database_url: &str) -> Result<PgPool, sqlx::Error> {
|
||||
PgPoolOptions::new()
|
||||
.max_connections(10)
|
||||
.acquire_timeout(Duration::from_secs(5))
|
||||
.connect(database_url)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
tracing::error!("Postgres connection error: {:?}", err);
|
||||
err
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn ensure_user_exists(pool: &PgPool, user_id: Uuid) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO auth.user (id)
|
||||
VALUES ($1)
|
||||
ON CONFLICT (id) DO NOTHING
|
||||
"#,
|
||||
user_id
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user