dynamic_db (#17)
All checks were successful
Release Tagging / release (push) Successful in 39s
Rust Build / Check (push) Successful in 41s
Rust Build / Test Suite (push) Successful in 48s
Rust Build / Rustfmt (push) Successful in 28s
Rust Build / Clippy (push) Successful in 48s
Rust Build / build (push) Successful in 1m13s
Rust Build / Check (pull_request) Successful in 57s
Rust Build / Test Suite (pull_request) Successful in 48s
Rust Build / Rustfmt (pull_request) Successful in 26s
Rust Build / Clippy (pull_request) Successful in 46s
Rust Build / build (pull_request) Successful in 1m12s

Reviewed-on: #17
Co-authored-by: phoenix <kundeng94@gmail.com>
Co-committed-by: phoenix <kundeng94@gmail.com>
This commit is contained in:
2025-04-05 01:30:35 +00:00
committed by phoenix
parent 6bdc893147
commit d7c3443022
11 changed files with 367 additions and 91 deletions

20
src/repo/mod.rs Normal file
View File

@@ -0,0 +1,20 @@
pub mod user {
use crate::models;
pub async fn insert(
pool: &sqlx::PgPool,
user: &models::common::User,
) -> Result<uuid::Uuid, sqlx::Error> {
let insert_sql = "INSERT INTO \"user\" (username, password) VALUES ($1, $2) RETURNING id";
match sqlx::query_scalar(insert_sql)
.bind(&user.username) // Bind the input message securely
.bind(&user.password)
.fetch_one(pool) // Execute and expect exactly ONE row with ONE column back
.await
{
Ok(o) => Ok(o),
Err(err) => Err(err), // _ => uuid::Uuid::nil(),
}
}
}