Skip to content

Commit 6e4a00e

Browse files
committed
update
1 parent e010975 commit 6e4a00e

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed
Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
1-
use crate::ctx::AppContext;
1+
use crate::storage::AppStorage;
22

33
pub struct AppService {
4-
pub ctx: &'static AppContext,
4+
pub storage: AppStorage,
55
}
66

77
impl AppService {
88
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);
1143
}
1244
}
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
pub use kv::*;
2+
pub use sql::*;
3+
4+
use crate::storage::db::AppSqlStorage;
5+
16
pub mod kv;
27
pub mod sql;
38

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+
}

crates/rs-tauri-vue/src-tauri/src/storage/sql/db.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ use crate::{storage::todo::TodoSqlScope, util};
1111

1212
// sql storage biz
1313
pub struct AppSqlStorage {
14-
pub g: SqlConn,
14+
g: SqlConn,
1515

1616
// biz units:
1717
pub todo: TodoSqlScope,
1818
}
1919

2020
impl AppSqlStorage {
21-
pub async fn new() -> anyhow::Result<Self> {
21+
pub async fn new() -> Self {
2222
let g = SqlConn::default().await;
2323

2424
let todo = TodoSqlScope::new(g.clone());
25-
26-
Ok(Self { g, todo })
25+
Self { g, todo }
2726
}
2827
}
2928

0 commit comments

Comments
 (0)