File tree Expand file tree Collapse file tree 5 files changed +36
-12
lines changed Expand file tree Collapse file tree 5 files changed +36
-12
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,13 @@ use scheduled_thread_pool::ScheduledThreadPool;
88{%- endif %}
99{%- endif %}
1010{%- if db_lib == "sqlx" %}
11+ {%- if db_type == "sqlite" %}
1112use sqlx::SqlitePool;
13+ {%- elsif db_type == "postgres" %}
14+ use sqlx::PgPool;
15+ {%- elsif db_type == "mysql" %}
16+ use sqlx::mysql::MySqlPool;
17+ {%- endif %}
1218{%- endif %}
1319use dotenvy::dotenv;
1420use salvo::catcher::Catcher;
@@ -87,12 +93,18 @@ async fn main() {
8793 {%- endif %}
8894
8995 {%- elsif db_lib == "sqlx" %}
96+ {%- if db_type == "sqlite" %}
9097 let sqlx_pool = SqlitePool::connect(&config::get().db.url)
98+ {%- elsif db_type == "postgres" %}
99+ let sqlx_pool = PgPool::connect(&config::get().db.url)
100+ {%- elsif db_type == "mysql" %}
101+ let sqlx_pool = MySqlPool::connect(&config::get().db.url)
102+ {%- endif %}
91103 .await
92104 .expect("Database connection failed.");
93105 crate::db::SQLX_POOL
94106 .set(sqlx_pool)
95- .expect("diesel pool should be set");
107+ .expect("sqlx pool should be set");
96108 {%- endif %}
97109
98110 let _guard = config.log.guard();
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ pub fn root() -> Router {
3030 . get ( user:: list_users)
3131 . post ( user:: create_user)
3232 . push (
33- Router :: with_path ( "{id }" )
33+ Router :: with_path ( "{user_id }" )
3434 . put ( user:: update_user)
3535 . delete ( user:: delete_user) ,
3636 ) ,
Original file line number Diff line number Diff line change @@ -53,4 +53,4 @@ fn default_connection_timeout() -> u64 {
5353}
5454fn default_statement_timeout ( ) -> u64 {
5555 30000
56- }
56+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ use std::sync::OnceLock;
2+
3+ {%- if db_type == "sqlite" %}
4+ use sqlx::SqlitePool;
5+ pub static SQLX_POOL: OnceLock<SqlitePool > = OnceLock::new();
6+ pub fn pool() -> & 'static SqlitePool {
7+ SQLX_POOL.get().expect("sqlx pool should be set")
8+ }
9+ {%- elsif db_type == "postgres" %}
10+ use sqlx::postgres::PgPool;
11+ pub static SQLX_POOL: OnceLock<PgPool > = OnceLock::new();
12+ pub fn pool() -> & 'static PgPool {
13+ SQLX_POOL.get().expect("sqlx pool should be set")
14+ }
15+ {%- elsif db_type == "mysql" %}
16+ use sqlx::mysql::MySqlPool;
17+ pub static SQLX_POOL: OnceLock<MySqlPool > = OnceLock::new();
18+ pub fn pool() -> & 'static MySqlPool {
19+ SQLX_POOL.get().expect("sqlx pool should be set")
20+ }
21+ {%- endif %}
You can’t perform that action at this time.
0 commit comments