Skip to content

Commit 55537b1

Browse files
committed
fix error
1 parent f1c7d44 commit 55537b1

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

templates/classic/_base/src/main.rs.liquid

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
{%- if db_lib == "diesel" %}
2-
{%- if db_type == "sqlite" %}
3-
{%- else %}
4-
{%- endif %}
5-
{%- endif %}
6-
{%- if db_lib == "sqlx" %}
7-
{%- if db_type == "sqlite" %}
8-
use sqlx::SqlitePool;
9-
{%- elsif db_type == "postgres" %}
10-
use sqlx::PgPool;
11-
{%- endif %}
12-
{%- endif %}
131
use dotenvy::dotenv;
142
use salvo::catcher::Catcher;
153
use salvo::conn::rustls::{Keycert, RustlsConfig};
@@ -55,10 +43,10 @@ async fn main() {
5543

5644
crate::config::init();
5745
let config = crate::config::get();
58-
{%- if db_lib == "rbatis" or db_lib == "seaorm" or db_lib == "mongodb" %}
59-
crate::db::init(&config.db).await;
60-
{%- else %}
46+
{%- if db_lib == "diesel" %}
6147
crate::db::init(&config.db);
48+
{%- else %}
49+
crate::db::init(&config.db).await;
6250
{%- endif %}
6351

6452
let _guard = config.log.guard();

templates/classic/seaorm/src/routers/user.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct CreateInData {
4545
pub async fn create_user(idata: JsonBody<CreateInData>) -> JsonResult<SafeUser> {
4646
let CreateInData { username, password } = idata.into_inner();
4747
let id = Ulid::new().to_string();
48-
let password = utils::hash_password(&password).await?;
48+
let password = utils::hash_password(&password)?;
4949
let conn = db::pool();
5050
let model = users::ActiveModel {
5151
id: Set(id.clone()),
@@ -78,7 +78,7 @@ pub async fn update_user(
7878
};
7979
let mut user: users::ActiveModel = user.into();
8080
user.username = Set(username.to_owned());
81-
user.password = Set(utils::hash_password(&password).await?);
81+
user.password = Set(utils::hash_password(&password)?);
8282

8383
let user: users::Model = user.update(conn).await?;
8484
json_ok(SafeUser {

templates/classic/sqlx/src/db/mod.rs.liquid

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ use std::sync::OnceLock;
33
{%- if db_type == "sqlite" %}
44
use sqlx::SqlitePool;
55

6+
use crate::config::DbConfig;
7+
68
pub static SQLX_POOL: OnceLock<SqlitePool> = OnceLock::new();
79

8-
pub fn init(config: &DbConfig) {
10+
pub async fn init(config: &DbConfig) {
911
let sqlx_pool = SqlitePool::connect(&config.url).await
1012
.expect("Database connection failed.");
1113
crate::db::SQLX_POOL
@@ -19,9 +21,11 @@ pub fn pool() -> &'static SqlitePool {
1921
{%- elsif db_type == "postgres" %}
2022
use sqlx::postgres::PgPool;
2123

24+
use crate::config::DbConfig;
25+
2226
pub static SQLX_POOL: OnceLock<PgPool> = OnceLock::new();
2327

24-
pub fn init(config: &DbConfig) {
28+
pub async fn init(config: &DbConfig) {
2529
let sqlx_pool = PgPool::connect(&config.url).await
2630
.expect("Database connection failed.");
2731
crate::db::SQLX_POOL
@@ -35,9 +39,11 @@ pub fn pool() -> &'static PgPool {
3539
{%- elsif db_type == "mysql" %}
3640
use sqlx::mysql::MySqlPool;
3741

42+
use crate::config::DbConfig;
43+
3844
pub static SQLX_POOL: OnceLock<MySqlPool> = OnceLock::new();
3945

40-
pub fn init(config: &DbConfig) {
46+
pub async fn init(config: &DbConfig) {
4147
let sqlx_pool = SqlitePool::connect(&config.url).await
4248
.expect("Database connection failed.");
4349
crate::db::SQLX_POOL

templates/classic/sqlx/src/routers/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct CreateInData {
4343
pub async fn create_user(idata: JsonBody<CreateInData>) -> JsonResult<SafeUser> {
4444
let CreateInData { username, password } = idata.into_inner();
4545
let id = Ulid::new().to_string();
46-
let password = utils::hash_password(&password).await?;
46+
let password = utils::hash_password(&password)?;
4747
let conn = db::pool();
4848
let _ = sqlx::query!(
4949
r#"

0 commit comments

Comments
 (0)