11use sqlx:: types:: time:: OffsetDateTime ;
2- use sqlx:: SqlitePool ;
2+ type Pool = sqlx:: Pool < sqlx :: Sqlite > ;
33
4- pub async fn setup_database ( pool : & SqlitePool ) -> Result < ( ) , sqlx:: Error > {
4+ pub async fn setup_database ( pool : & Pool ) -> Result < ( ) , sqlx:: Error > {
55 sqlx:: query!(
66 "CREATE TABLE IF NOT EXISTS invites (
77 id TEXT PRIMARY KEY,
@@ -19,14 +19,14 @@ pub async fn setup_database(pool: &SqlitePool) -> Result<(), sqlx::Error> {
1919 Ok ( ( ) )
2020}
2121
22- pub async fn create_pool ( database_path : & str ) -> Result < SqlitePool , sqlx:: Error > {
23- let pool = SqlitePool :: connect ( & format ! ( "sqlite:{}" , database_path) ) . await ?;
22+ pub async fn create_pool ( database_path : & str ) -> Result < Pool , sqlx:: Error > {
23+ let pool = Pool :: connect ( database_path) . await ?;
2424 setup_database ( & pool) . await ?;
2525 Ok ( pool)
2626}
2727
2828pub async fn create_invite (
29- pool : & SqlitePool ,
29+ pool : & Pool ,
3030 invite_id : & str ,
3131 guild_id : & str ,
3232 creator_id : & str ,
@@ -45,7 +45,7 @@ pub async fn create_invite(
4545}
4646
4747pub async fn get_unused_invite (
48- pool : & SqlitePool ,
48+ pool : & Pool ,
4949 invite_id : & str ,
5050) -> Result < Option < InviteRecord > , sqlx:: Error > {
5151 sqlx:: query_as!(
@@ -58,7 +58,7 @@ pub async fn get_unused_invite(
5858}
5959
6060pub async fn update_invite_code (
61- pool : & SqlitePool ,
61+ pool : & Pool ,
6262 invite_id : & str ,
6363 discord_code : & str ,
6464) -> Result < ( ) , sqlx:: Error > {
@@ -73,7 +73,7 @@ pub async fn update_invite_code(
7373}
7474
7575pub async fn count_used_invites (
76- pool : & SqlitePool ,
76+ pool : & Pool ,
7777 creator_id : & str ,
7878 guild_id : & str ,
7979 days : i32 ,
@@ -112,7 +112,7 @@ pub struct InviteInfo {
112112}
113113
114114pub async fn get_user_invite_info (
115- pool : & SqlitePool ,
115+ pool : & Pool ,
116116 user_id : & str ,
117117) -> Result < Option < InviteInfo > , sqlx:: Error > {
118118 sqlx:: query_as!(
@@ -131,7 +131,7 @@ pub async fn get_user_invite_info(
131131
132132// 新增:記錄使用邀請的用戶
133133pub async fn record_invite_use (
134- pool : & SqlitePool ,
134+ pool : & Pool ,
135135 invite_id : & str ,
136136 user_id : & str ,
137137) -> Result < ( ) , sqlx:: Error > {
@@ -152,7 +152,7 @@ pub async fn record_invite_use(
152152}
153153
154154pub async fn find_invite_by_code (
155- pool : & SqlitePool ,
155+ pool : & Pool ,
156156 discord_code : & str ,
157157) -> Result < Option < String > , sqlx:: Error > {
158158 sqlx:: query_scalar!(
@@ -171,7 +171,7 @@ pub struct InviteLeaderboardEntry {
171171}
172172
173173pub async fn get_invite_leaderboard (
174- pool : & SqlitePool ,
174+ pool : & Pool ,
175175 guild_id : & str ,
176176 days : i32 ,
177177) -> Result < Vec < InviteLeaderboardEntry > , sqlx:: Error > {
@@ -203,10 +203,9 @@ pub async fn get_invite_leaderboard(
203203#[ cfg( test) ]
204204mod tests {
205205 use super :: * ;
206- use sqlx:: SqlitePool ;
207206 use uuid:: Uuid ;
208207
209- async fn setup_test_db ( ) -> SqlitePool {
208+ async fn setup_test_db ( ) -> Pool {
210209 let db_url = format ! ( "sqlite:file:{}?mode=memory" , Uuid :: new_v4( ) ) ;
211210 let pool = create_pool ( & db_url) . await . unwrap ( ) ;
212211 sqlx:: migrate!( ) . run ( & pool) . await . unwrap ( ) ;
0 commit comments