Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

mv kv to flowy-database

appflowydfa9c04f5a2b
diff --git a/backend/Cargo.lock b/backend/Cargo.lock
index ed95e928da..3062c72aa4 100644
--- a/backend/Cargo.lock
+++ b/backend/Cargo.lock
@@ -1279,7 +1279,9 @@ dependencies = [
"diesel",
"diesel_derives",
"diesel_migrations",
+ "lazy_static",
"lib-sqlite",
+ "log",
]
[[package]]
@@ -1942,13 +1944,8 @@ version = "0.1.0"
dependencies = [
"bytes",
"chrono",
- "diesel",
- "diesel_derives",
- "diesel_migrations",
"flowy-derive",
"futures-core",
- "lazy_static",
- "lib-sqlite",
"log",
"pin-project 1.0.8",
"protobuf",
diff --git a/frontend/rust-lib/flowy-core/src/services/view/controller.rs b/frontend/rust-lib/flowy-core/src/services/view/controller.rs
index 80ca0677cf..d6ff221383 100644
--- a/frontend/rust-lib/flowy-core/src/services/view/controller.rs
+++ b/frontend/rust-lib/flowy-core/src/services/view/controller.rs
@@ -19,8 +19,8 @@ use crate::{
},
};
use flowy_core_infra::entities::share::{ExportData, ExportParams};
+use flowy_database::kv::KV;
use flowy_document::module::FlowyDocument;
-use lib_infra::kv::KV;
const LATEST_VIEW_ID: &str = "latest_view_id";
diff --git a/frontend/rust-lib/flowy-core/src/services/workspace/controller.rs b/frontend/rust-lib/flowy-core/src/services/workspace/controller.rs
index 2edf7eea57..aebda93def 100644
--- a/frontend/rust-lib/flowy-core/src/services/workspace/controller.rs
+++ b/frontend/rust-lib/flowy-core/src/services/workspace/controller.rs
@@ -10,8 +10,7 @@ use crate::{
},
};
use flowy_core_infra::entities::{app::RepeatedApp, workspace::*};
-use flowy_database::SqliteConnection;
-use lib_infra::kv::KV;
+use flowy_database::{kv::KV, SqliteConnection};
use std::sync::Arc;
pub struct WorkspaceController {
diff --git a/frontend/rust-lib/flowy-database/Cargo.toml b/frontend/rust-lib/flowy-database/Cargo.toml
index 35f68c1480..c2e3f64fd4 100644
--- a/frontend/rust-lib/flowy-database/Cargo.toml
+++ b/frontend/rust-lib/flowy-database/Cargo.toml
@@ -9,4 +9,6 @@ edition = "2018"
diesel = {version = "1.4.8", features = ["sqlite"]}
diesel_derives = {version = "1.4.1", features = ["sqlite"]}
diesel_migrations = {version = "1.4.0", features = ["sqlite"]}
-lib-sqlite = { path = "../../../shared-lib/lib-sqlite" }
\ No newline at end of file
+lib-sqlite = { path = "../../../shared-lib/lib-sqlite" }
+log = "0.4"
+lazy_static = "1.4.0"
\ No newline at end of file
diff --git a/frontend/rust-lib/lib-infra/src/kv/kv.rs b/frontend/rust-lib/flowy-database/src/kv/kv.rs
similarity index 95%
rename from frontend/rust-lib/lib-infra/src/kv/kv.rs
rename to frontend/rust-lib/flowy-database/src/kv/kv.rs
index c9303e7520..7dcb5b86c4 100644
--- a/frontend/rust-lib/lib-infra/src/kv/kv.rs
+++ b/frontend/rust-lib/flowy-database/src/kv/kv.rs
@@ -1,7 +1,6 @@
use crate::kv::schema::{kv_table, kv_table::dsl, KV_SQL};
use ::diesel::{query_dsl::*, ExpressionMethods};
use diesel::{Connection, SqliteConnection};
-use flowy_derive::ProtoBuf;
use lazy_static::lazy_static;
use lib_sqlite::{DBConnection, Database, PoolConfig};
use std::{collections::HashMap, path::Path, sync::RwLock};
@@ -178,23 +177,14 @@ fn get_connection() -> Result<DBConnection, String> {
}
}
-#[derive(Clone, Debug, ProtoBuf, Default, Queryable, Identifiable, Insertable, AsChangeset)]
+#[derive(Clone, Debug, Default, Queryable, Identifiable, Insertable, AsChangeset)]
#[table_name = "kv_table"]
#[primary_key(key)]
pub struct KeyValue {
- #[pb(index = 1)]
pub key: String,
-
- #[pb(index = 2, one_of)]
pub str_value: Option<String>,
-
- #[pb(index = 3, one_of)]
pub int_value: Option<i64>,
-
- #[pb(index = 4, one_of)]
pub float_value: Option<f64>,
-
- #[pb(index = 5, one_of)]
pub bool_value: Option<bool>,
}
diff --git a/frontend/rust-lib/lib-infra/src/kv/mod.rs b/frontend/rust-lib/flowy-database/src/kv/mod.rs
similarity index 100%
rename from frontend/rust-lib/lib-infra/src/kv/mod.rs
rename to frontend/rust-lib/flowy-database/src/kv/mod.rs
diff --git a/frontend/rust-lib/lib-infra/src/kv/schema.rs b/frontend/rust-lib/flowy-database/src/kv/schema.rs
similarity index 100%
rename from frontend/rust-lib/lib-infra/src/kv/schema.rs
rename to frontend/rust-lib/flowy-database/src/kv/schema.rs
diff --git a/frontend/rust-lib/flowy-database/src/lib.rs b/frontend/rust-lib/flowy-database/src/lib.rs
index 4d50552f55..bfdec920d4 100644
--- a/frontend/rust-lib/flowy-database/src/lib.rs
+++ b/frontend/rust-lib/flowy-database/src/lib.rs
@@ -1,3 +1,12 @@
+pub use diesel::*;
+pub use diesel_derives::*;
+use diesel_migrations::*;
+use std::{fmt::Debug, io, path::Path};
+pub mod kv;
+
+use lib_sqlite::PoolConfig;
+pub use lib_sqlite::{ConnectionPool, DBConnection, Database};
+
pub mod schema;
#[macro_use]
@@ -5,25 +14,17 @@ pub mod macros;
#[macro_use]
extern crate diesel;
-pub use diesel::*;
-
#[macro_use]
extern crate diesel_derives;
-pub use diesel_derives::*;
-
#[macro_use]
extern crate diesel_migrations;
-pub use lib_sqlite::{ConnectionPool, DBConnection, Database};
pub type Error = diesel::result::Error;
-use diesel_migrations::*;
-use lib_sqlite::PoolConfig;
-use std::{fmt::Debug, io, path::Path};
-
pub mod prelude {
- pub use super::UserDatabaseConnection;
pub use diesel::{query_dsl::*, BelongingToDsl, ExpressionMethods, RunQueryDsl};
+
+ pub use super::UserDatabaseConnection;
}
embed_migrations!("../flowy-database/migrations/");
diff --git a/frontend/rust-lib/flowy-sdk/src/lib.rs b/frontend/rust-lib/flowy-sdk/src/lib.rs
index 2f2322d478..0e3a19bad2 100644
--- a/frontend/rust-lib/flowy-sdk/src/lib.rs
+++ b/frontend/rust-lib/flowy-sdk/src/lib.rs
@@ -148,7 +148,7 @@ async fn _listen_network_status(mut subscribe: broadcast::Receiver<NetworkType>,
}
fn init_kv(root: &str) {
- match lib_infra::kv::KV::init(root) {
+ match flowy_database::kv::KV::init(root) {
Ok(_) => {},
Err(e) => tracing::error!("Init kv store failedL: {}", e),
}
diff --git a/frontend/rust-lib/flowy-test/src/helper.rs b/frontend/rust-lib/flowy-test/src/helper.rs
index cfec412418..a533e8473f 100644
--- a/frontend/rust-lib/flowy-test/src/helper.rs
+++ b/frontend/rust-lib/flowy-test/src/helper.rs
@@ -1,5 +1,5 @@
-use crate::prelude::*;
-use bytes::Bytes;
+use std::{fs, path::PathBuf, sync::Arc};
+
use flowy_collaboration::entities::doc::Doc;
use flowy_core::{
entities::{
@@ -8,7 +8,7 @@ use flowy_core::{
view::*,
workspace::{CreateWorkspaceRequest, QueryWorkspaceRequest, Workspace, *},
},
- errors::{ErrorCode, WorkspaceError},
+ errors::ErrorCode,
event::WorkspaceEvent::{CreateWorkspace, OpenWorkspace, *},
};
use flowy_user::{
@@ -17,8 +17,9 @@ use flowy_user::{
event::UserEvent::{InitUser, SignIn, SignOut, SignUp},
};
use lib_dispatch::prelude::{EventDispatcher, ModuleRequest, ToBytes};
-use lib_infra::{kv::KV, uuid};
-use std::{fs, path::PathBuf, sync::Arc};
+use lib_infra::uuid;
+
+use crate::prelude::*;
pub struct WorkspaceTest {
pub sdk: FlowySDKTest,
@@ -298,46 +299,6 @@ pub fn login_email() -> String { "[email protected]".to_string() }
pub fn login_password() -> String { "HelloWorld!123".to_string() }
-const DEFAULT_WORKSPACE_NAME: &str = "My workspace";
-const DEFAULT_WORKSPACE_DESC: &str = "This is your first workspace";
-const DEFAULT_WORKSPACE: &str = "Default_Workspace";
-
-#[allow(dead_code)]
-pub(crate) fn create_default_workspace_if_need(dispatch: Arc<EventDispatcher>, user_id: &str) -> Result<(), UserError> {
- let key = format!("{}{}", user_id, DEFAULT_WORKSPACE);
- if KV::get_bool(&key).unwrap_or(false) {
- return Err(UserError::internal());
- }
- KV::set_bool(&key, true);
-
- let payload: Bytes = CreateWorkspaceRequest {
- name: DEFAULT_WORKSPACE_NAME.to_string(),
- desc: DEFAULT_WORKSPACE_DESC.to_string(),
- }
- .into_bytes()
- .unwrap();
-
- let request = ModuleRequest::new(CreateWorkspace).payload(payload);
- let result = EventDispatcher::sync_send(dispatch.clone(), request)
- .parse::<Workspace, WorkspaceError>()
- .map_err(|e| UserError::internal().context(e))?;
-
- let workspace = result.map_err(|e| UserError::internal().context(e))?;
- let query: Bytes = QueryWorkspaceRequest {
- workspace_id: Some(workspace.id),
- }
- .into_bytes()
- .unwrap();
-
- let request = ModuleRequest::new(OpenWorkspace).payload(query);
- let _result = EventDispatcher::sync_send(dispatch, request)
- .parse::<Workspace, WorkspaceError>()
- .unwrap()
- .unwrap();
-
- Ok(())
-}
-
pub struct SignUpContext {
pub user_profile: UserProfile,
pub password: String,
diff --git a/frontend/rust-lib/flowy-user/src/services/user/user_session.rs b/frontend/rust-lib/flowy-user/src/services/user/user_session.rs
index 010e462801..e0c99b65e6 100644
--- a/frontend/rust-lib/flowy-user/src/services/user/user_session.rs
+++ b/frontend/rust-lib/flowy-user/src/services/user/user_session.rs
@@ -1,22 +1,12 @@
-use crate::{
- entities::{SignInParams, SignUpParams, UpdateUserParams, UserProfile},
- errors::{ErrorCode, UserError},
- services::user::database::UserDB,
- sql_tables::{UserTable, UserTableChangeset},
-};
+use std::sync::Arc;
+
+use parking_lot::RwLock;
+use serde::{Deserialize, Serialize};
+use tokio::sync::{broadcast, mpsc};
-use crate::{
- notify::*,
- services::{
- server::{construct_user_server, Server},
- user::{
- notifier::UserNotifier,
- ws_manager::{FlowyWsSender, WsManager},
- },
- },
-};
use backend_service::configuration::ClientServerConfiguration;
use flowy_database::{
+ kv::KV,
query_dsl::*,
schema::{user_table, user_table::dsl},
DBConnection,
@@ -24,13 +14,24 @@ use flowy_database::{
UserDatabaseConnection,
};
use flowy_user_infra::entities::{SignInResponse, SignUpResponse};
-use lib_infra::{entities::network_state::NetworkState, kv::KV};
+use lib_infra::entities::network_state::NetworkState;
use lib_sqlite::ConnectionPool;
use lib_ws::{WsConnectState, WsMessageHandler};
-use parking_lot::RwLock;
-use serde::{Deserialize, Serialize};
-use std::sync::Arc;
-use tokio::sync::{broadcast, mpsc};
+
+use crate::{
+ entities::{SignInParams, SignUpParams, UpdateUserParams, UserProfile},
+ errors::{ErrorCode, UserError},
+ notify::*,
+ services::{
+ server::{construct_user_server, Server},
+ user::{
+ database::UserDB,
+ notifier::UserNotifier,
+ ws_manager::{FlowyWsSender, WsManager},
+ },
+ },
+ sql_tables::{UserTable, UserTableChangeset},
+};
pub struct UserSessionConfig {
root_dir: String,
diff --git a/frontend/rust-lib/lib-infra/Cargo.toml b/frontend/rust-lib/lib-infra/Cargo.toml
index ce43059378..57a7a2dee3 100644
--- a/frontend/rust-lib/lib-infra/Cargo.toml
+++ b/frontend/rust-lib/lib-infra/Cargo.toml
@@ -7,12 +7,7 @@ edition = "2018"
[dependencies]
uuid = { version = "0.8", features = ["serde", "v4"] }
-diesel = {version = "1.4.8", features = ["sqlite"]}
-diesel_derives = {version = "1.4.1", features = ["sqlite"]}
-diesel_migrations = {version = "1.4.0", features = ["sqlite"]}
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
-lib-sqlite = { path = "../../../shared-lib/lib-sqlite" }
-lazy_static = "1.4.0"
protobuf = {version = "2.18.0"}
log = "0.4.14"
chrono = "0.4.19"
diff --git a/frontend/rust-lib/lib-infra/src/lib.rs b/frontend/rust-lib/lib-infra/src/lib.rs
index a934281b0e..681f4aa7f2 100644
--- a/frontend/rust-lib/lib-infra/src/lib.rs
+++ b/frontend/rust-lib/lib-infra/src/lib.rs
@@ -1,12 +1,5 @@
-#[macro_use]
-extern crate diesel;
-
-#[macro_use]
-extern crate diesel_derives;
-
pub mod entities;
pub mod future;
-pub mod kv;
mod protobuf;
pub mod retry;
diff --git a/shared-lib/Cargo.lock b/shared-lib/Cargo.lock
index e3a7e34a49..34d88e6bf5 100644
--- a/shared-lib/Cargo.lock
+++ b/shared-lib/Cargo.lock
@@ -1132,13 +1132,8 @@ version = "0.1.0"
dependencies = [
"bytes",
"chrono",
- "diesel",
- "diesel_derives",
- "diesel_migrations",
"flowy-derive",
"futures-core",
- "lazy_static",
- "lib-sqlite",
"log",
"pin-project",
"protobuf",