feat: add user in db

This commit is contained in:
2026-05-06 15:22:49 +02:00
parent 7f77bfef4e
commit d7ddc087a6
11 changed files with 901 additions and 35 deletions
+1
View File
@@ -0,0 +1 @@
pub mod postgres;
+2
View File
@@ -0,0 +1,2 @@
pub mod pool;
pub mod user_repository;
+14
View File
@@ -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
})
}
+17
View File
@@ -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(())
}