File tree Expand file tree Collapse file tree 3 files changed +56
-10
lines changed
crates/rs-tauri-vue/src-tauri/src Expand file tree Collapse file tree 3 files changed +56
-10
lines changed Original file line number Diff line number Diff line change 1
- use crate :: ctx :: AppContext ;
1
+ use crate :: storage :: AppStorage ;
2
2
3
3
pub struct AppService {
4
- pub ctx : & ' static AppContext ,
4
+ pub storage : AppStorage ,
5
5
}
6
6
7
7
impl AppService {
8
8
pub async fn new ( ) -> Self {
9
- let ctx = AppContext :: global ( ) . await ;
10
- Self { ctx }
9
+ let storage = AppStorage :: new ( ) . await ;
10
+ Self { storage }
11
+ }
12
+ }
13
+
14
+ #[ cfg( test) ]
15
+ mod test {
16
+ use crate :: proto:: TodoEntity ;
17
+
18
+ use super :: * ;
19
+
20
+ #[ tokio:: test]
21
+ async fn test_new_service ( ) {
22
+ let service = AppService :: new ( ) . await ;
23
+
24
+ let ret = service
25
+ . storage
26
+ . sql
27
+ . todo
28
+ . add_todo ( & TodoEntity {
29
+ id : 0 ,
30
+ title : "add todo, by service" . to_string ( ) ,
31
+ description : "test desc" . to_string ( ) ,
32
+ done : false ,
33
+ completed : false ,
34
+ } )
35
+ . await
36
+ . unwrap ( ) ;
37
+
38
+ println ! ( "service add todo: {}" , ret) ;
39
+
40
+ let todo = service. storage . sql . todo . get_todo ( ret) . await . unwrap ( ) ;
41
+
42
+ println ! ( "service get todo: {:?}" , todo) ;
11
43
}
12
44
}
Original file line number Diff line number Diff line change
1
+ pub use kv:: * ;
2
+ pub use sql:: * ;
3
+
4
+ use crate :: storage:: db:: AppSqlStorage ;
5
+
1
6
pub mod kv;
2
7
pub mod sql;
3
8
4
- pub use kv:: * ;
5
- pub use sql:: * ;
9
+ pub struct AppStorage {
10
+ pub kv : AppKvStorage ,
11
+ pub sql : AppSqlStorage ,
12
+ }
13
+
14
+ impl AppStorage {
15
+ pub async fn new ( ) -> Self {
16
+ let kv = AppKvStorage :: default ( ) ;
17
+ let sql = AppSqlStorage :: new ( ) . await ;
18
+ Self { kv, sql }
19
+ }
20
+ }
Original file line number Diff line number Diff line change @@ -11,19 +11,18 @@ use crate::{storage::todo::TodoSqlScope, util};
11
11
12
12
// sql storage biz
13
13
pub struct AppSqlStorage {
14
- pub g : SqlConn ,
14
+ g : SqlConn ,
15
15
16
16
// biz units:
17
17
pub todo : TodoSqlScope ,
18
18
}
19
19
20
20
impl AppSqlStorage {
21
- pub async fn new ( ) -> anyhow :: Result < Self > {
21
+ pub async fn new ( ) -> Self {
22
22
let g = SqlConn :: default ( ) . await ;
23
23
24
24
let todo = TodoSqlScope :: new ( g. clone ( ) ) ;
25
-
26
- Ok ( Self { g, todo } )
25
+ Self { g, todo }
27
26
}
28
27
}
29
28
You can’t perform that action at this time.
0 commit comments