访问users数据库

This commit is contained in:
2025-09-05 15:10:30 +08:00
parent 7570bfd50b
commit f567e66485
6 changed files with 1266 additions and 70 deletions

10
src/db.rs Normal file
View File

@@ -0,0 +1,10 @@
use sqlx::postgres::PgPool; // 修改导入路径
use std::env;
pub async fn create_pool() -> Result<PgPool, sqlx::Error> {
dotenvy::dotenv().ok();
let database_url = env::var("DATABASE_URL")
.expect("DATABASE_URL must be set in .env file");
PgPool::connect(&database_url).await
}