1
1
use sqlx:: { Acquire , Executor , Statement } ;
2
2
3
- use crate :: { proto:: TodoEntity , storage:: db:: AppSqlStorage } ;
3
+ use crate :: { proto:: TodoEntity , storage:: db:: SqlConn } ;
4
4
5
- pub struct TodoStorage {
6
- pub db : AppSqlStorage ,
5
+ pub struct TodoSqlScope {
6
+ pub g : SqlConn ,
7
7
}
8
8
9
- impl TodoStorage {
10
- pub fn new ( db : AppSqlStorage ) -> Self {
11
- Self { db }
9
+ impl TodoSqlScope {
10
+ pub fn new ( g : SqlConn ) -> Self {
11
+ Self { g }
12
12
}
13
13
14
14
pub async fn add_todo ( & self , todo : & TodoEntity ) -> anyhow:: Result < i64 > {
15
- let mut conn = self . db . conn . acquire ( ) . await ?;
15
+ let mut conn = self . g . conn . acquire ( ) . await ?;
16
16
17
17
// Insert the task, then obtain the ID of this row
18
18
let id = sqlx:: query!(
@@ -31,7 +31,7 @@ impl TodoStorage {
31
31
}
32
32
33
33
pub async fn list_todo ( & self ) -> anyhow:: Result < Vec < TodoEntity > > {
34
- let mut conn = self . db . conn . acquire ( ) . await ?;
34
+ let mut conn = self . g . conn . acquire ( ) . await ?;
35
35
36
36
let rows = sqlx:: query!(
37
37
r#"
@@ -59,7 +59,7 @@ ORDER BY id
59
59
}
60
60
61
61
pub async fn get_todo ( & self , id : i64 ) -> anyhow:: Result < TodoEntity > {
62
- let mut conn = self . db . conn . acquire ( ) . await ?;
62
+ let mut conn = self . g . conn . acquire ( ) . await ?;
63
63
64
64
let row =
65
65
sqlx:: query!( r#"SELECT id, title, description, completed FROM todos WHERE id = ?"# , id)
@@ -84,11 +84,11 @@ mod test {
84
84
85
85
use super :: * ;
86
86
87
- async fn setup ( ) -> TodoStorage {
88
- let mut db = AppSqlStorage :: new ( "test.db" ) . await ;
87
+ async fn setup ( ) -> TodoSqlScope {
88
+ let mut db = SqlConn :: new ( "test.db" ) . await ;
89
89
db. init_migrations ( ) . await ;
90
90
91
- TodoStorage :: new ( db)
91
+ TodoSqlScope :: new ( db)
92
92
}
93
93
94
94
#[ tokio:: test]
0 commit comments