mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
mv kv to flowy-database
This commit is contained in:
parent
0231ad3adf
commit
dfa9c04f5a
7
backend/Cargo.lock
generated
7
backend/Cargo.lock
generated
@ -1279,7 +1279,9 @@ dependencies = [
|
|||||||
"diesel",
|
"diesel",
|
||||||
"diesel_derives",
|
"diesel_derives",
|
||||||
"diesel_migrations",
|
"diesel_migrations",
|
||||||
|
"lazy_static",
|
||||||
"lib-sqlite",
|
"lib-sqlite",
|
||||||
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1942,13 +1944,8 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel",
|
|
||||||
"diesel_derives",
|
|
||||||
"diesel_migrations",
|
|
||||||
"flowy-derive",
|
"flowy-derive",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"lazy_static",
|
|
||||||
"lib-sqlite",
|
|
||||||
"log",
|
"log",
|
||||||
"pin-project 1.0.8",
|
"pin-project 1.0.8",
|
||||||
"protobuf",
|
"protobuf",
|
||||||
|
@ -19,8 +19,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use flowy_core_infra::entities::share::{ExportData, ExportParams};
|
use flowy_core_infra::entities::share::{ExportData, ExportParams};
|
||||||
|
use flowy_database::kv::KV;
|
||||||
use flowy_document::module::FlowyDocument;
|
use flowy_document::module::FlowyDocument;
|
||||||
use lib_infra::kv::KV;
|
|
||||||
|
|
||||||
const LATEST_VIEW_ID: &str = "latest_view_id";
|
const LATEST_VIEW_ID: &str = "latest_view_id";
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use flowy_core_infra::entities::{app::RepeatedApp, workspace::*};
|
use flowy_core_infra::entities::{app::RepeatedApp, workspace::*};
|
||||||
use flowy_database::SqliteConnection;
|
use flowy_database::{kv::KV, SqliteConnection};
|
||||||
use lib_infra::kv::KV;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct WorkspaceController {
|
pub struct WorkspaceController {
|
||||||
|
@ -10,3 +10,5 @@ diesel = {version = "1.4.8", features = ["sqlite"]}
|
|||||||
diesel_derives = {version = "1.4.1", features = ["sqlite"]}
|
diesel_derives = {version = "1.4.1", features = ["sqlite"]}
|
||||||
diesel_migrations = {version = "1.4.0", features = ["sqlite"]}
|
diesel_migrations = {version = "1.4.0", features = ["sqlite"]}
|
||||||
lib-sqlite = { path = "../../../shared-lib/lib-sqlite" }
|
lib-sqlite = { path = "../../../shared-lib/lib-sqlite" }
|
||||||
|
log = "0.4"
|
||||||
|
lazy_static = "1.4.0"
|
@ -1,7 +1,6 @@
|
|||||||
use crate::kv::schema::{kv_table, kv_table::dsl, KV_SQL};
|
use crate::kv::schema::{kv_table, kv_table::dsl, KV_SQL};
|
||||||
use ::diesel::{query_dsl::*, ExpressionMethods};
|
use ::diesel::{query_dsl::*, ExpressionMethods};
|
||||||
use diesel::{Connection, SqliteConnection};
|
use diesel::{Connection, SqliteConnection};
|
||||||
use flowy_derive::ProtoBuf;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use lib_sqlite::{DBConnection, Database, PoolConfig};
|
use lib_sqlite::{DBConnection, Database, PoolConfig};
|
||||||
use std::{collections::HashMap, path::Path, sync::RwLock};
|
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"]
|
#[table_name = "kv_table"]
|
||||||
#[primary_key(key)]
|
#[primary_key(key)]
|
||||||
pub struct KeyValue {
|
pub struct KeyValue {
|
||||||
#[pb(index = 1)]
|
|
||||||
pub key: String,
|
pub key: String,
|
||||||
|
|
||||||
#[pb(index = 2, one_of)]
|
|
||||||
pub str_value: Option<String>,
|
pub str_value: Option<String>,
|
||||||
|
|
||||||
#[pb(index = 3, one_of)]
|
|
||||||
pub int_value: Option<i64>,
|
pub int_value: Option<i64>,
|
||||||
|
|
||||||
#[pb(index = 4, one_of)]
|
|
||||||
pub float_value: Option<f64>,
|
pub float_value: Option<f64>,
|
||||||
|
|
||||||
#[pb(index = 5, one_of)]
|
|
||||||
pub bool_value: Option<bool>,
|
pub bool_value: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
@ -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;
|
pub mod schema;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -5,25 +14,17 @@ pub mod macros;
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
pub use diesel::*;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel_derives;
|
extern crate diesel_derives;
|
||||||
pub use diesel_derives::*;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel_migrations;
|
extern crate diesel_migrations;
|
||||||
|
|
||||||
pub use lib_sqlite::{ConnectionPool, DBConnection, Database};
|
|
||||||
pub type Error = diesel::result::Error;
|
pub type Error = diesel::result::Error;
|
||||||
|
|
||||||
use diesel_migrations::*;
|
|
||||||
use lib_sqlite::PoolConfig;
|
|
||||||
use std::{fmt::Debug, io, path::Path};
|
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use super::UserDatabaseConnection;
|
|
||||||
pub use diesel::{query_dsl::*, BelongingToDsl, ExpressionMethods, RunQueryDsl};
|
pub use diesel::{query_dsl::*, BelongingToDsl, ExpressionMethods, RunQueryDsl};
|
||||||
|
|
||||||
|
pub use super::UserDatabaseConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
embed_migrations!("../flowy-database/migrations/");
|
embed_migrations!("../flowy-database/migrations/");
|
||||||
|
@ -148,7 +148,7 @@ async fn _listen_network_status(mut subscribe: broadcast::Receiver<NetworkType>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init_kv(root: &str) {
|
fn init_kv(root: &str) {
|
||||||
match lib_infra::kv::KV::init(root) {
|
match flowy_database::kv::KV::init(root) {
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => tracing::error!("Init kv store failedL: {}", e),
|
Err(e) => tracing::error!("Init kv store failedL: {}", e),
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use std::{fs, path::PathBuf, sync::Arc};
|
||||||
use bytes::Bytes;
|
|
||||||
use flowy_collaboration::entities::doc::Doc;
|
use flowy_collaboration::entities::doc::Doc;
|
||||||
use flowy_core::{
|
use flowy_core::{
|
||||||
entities::{
|
entities::{
|
||||||
@ -8,7 +8,7 @@ use flowy_core::{
|
|||||||
view::*,
|
view::*,
|
||||||
workspace::{CreateWorkspaceRequest, QueryWorkspaceRequest, Workspace, *},
|
workspace::{CreateWorkspaceRequest, QueryWorkspaceRequest, Workspace, *},
|
||||||
},
|
},
|
||||||
errors::{ErrorCode, WorkspaceError},
|
errors::ErrorCode,
|
||||||
event::WorkspaceEvent::{CreateWorkspace, OpenWorkspace, *},
|
event::WorkspaceEvent::{CreateWorkspace, OpenWorkspace, *},
|
||||||
};
|
};
|
||||||
use flowy_user::{
|
use flowy_user::{
|
||||||
@ -17,8 +17,9 @@ use flowy_user::{
|
|||||||
event::UserEvent::{InitUser, SignIn, SignOut, SignUp},
|
event::UserEvent::{InitUser, SignIn, SignOut, SignUp},
|
||||||
};
|
};
|
||||||
use lib_dispatch::prelude::{EventDispatcher, ModuleRequest, ToBytes};
|
use lib_dispatch::prelude::{EventDispatcher, ModuleRequest, ToBytes};
|
||||||
use lib_infra::{kv::KV, uuid};
|
use lib_infra::uuid;
|
||||||
use std::{fs, path::PathBuf, sync::Arc};
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct WorkspaceTest {
|
pub struct WorkspaceTest {
|
||||||
pub sdk: FlowySDKTest,
|
pub sdk: FlowySDKTest,
|
||||||
@ -298,46 +299,6 @@ pub fn login_email() -> String { "annie2@appflowy.io".to_string() }
|
|||||||
|
|
||||||
pub fn login_password() -> String { "HelloWorld!123".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 struct SignUpContext {
|
||||||
pub user_profile: UserProfile,
|
pub user_profile: UserProfile,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
|
@ -1,22 +1,12 @@
|
|||||||
use crate::{
|
use std::sync::Arc;
|
||||||
entities::{SignInParams, SignUpParams, UpdateUserParams, UserProfile},
|
|
||||||
errors::{ErrorCode, UserError},
|
use parking_lot::RwLock;
|
||||||
services::user::database::UserDB,
|
use serde::{Deserialize, Serialize};
|
||||||
sql_tables::{UserTable, UserTableChangeset},
|
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 backend_service::configuration::ClientServerConfiguration;
|
||||||
use flowy_database::{
|
use flowy_database::{
|
||||||
|
kv::KV,
|
||||||
query_dsl::*,
|
query_dsl::*,
|
||||||
schema::{user_table, user_table::dsl},
|
schema::{user_table, user_table::dsl},
|
||||||
DBConnection,
|
DBConnection,
|
||||||
@ -24,13 +14,24 @@ use flowy_database::{
|
|||||||
UserDatabaseConnection,
|
UserDatabaseConnection,
|
||||||
};
|
};
|
||||||
use flowy_user_infra::entities::{SignInResponse, SignUpResponse};
|
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_sqlite::ConnectionPool;
|
||||||
use lib_ws::{WsConnectState, WsMessageHandler};
|
use lib_ws::{WsConnectState, WsMessageHandler};
|
||||||
use parking_lot::RwLock;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use crate::{
|
||||||
use std::sync::Arc;
|
entities::{SignInParams, SignUpParams, UpdateUserParams, UserProfile},
|
||||||
use tokio::sync::{broadcast, mpsc};
|
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 {
|
pub struct UserSessionConfig {
|
||||||
root_dir: String,
|
root_dir: String,
|
||||||
|
@ -7,12 +7,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
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" }
|
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
|
||||||
lib-sqlite = { path = "../../../shared-lib/lib-sqlite" }
|
|
||||||
lazy_static = "1.4.0"
|
|
||||||
protobuf = {version = "2.18.0"}
|
protobuf = {version = "2.18.0"}
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate diesel;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate diesel_derives;
|
|
||||||
|
|
||||||
pub mod entities;
|
pub mod entities;
|
||||||
pub mod future;
|
pub mod future;
|
||||||
pub mod kv;
|
|
||||||
mod protobuf;
|
mod protobuf;
|
||||||
pub mod retry;
|
pub mod retry;
|
||||||
|
|
||||||
|
5
shared-lib/Cargo.lock
generated
5
shared-lib/Cargo.lock
generated
@ -1132,13 +1132,8 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel",
|
|
||||||
"diesel_derives",
|
|
||||||
"diesel_migrations",
|
|
||||||
"flowy-derive",
|
"flowy-derive",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"lazy_static",
|
|
||||||
"lib-sqlite",
|
|
||||||
"log",
|
"log",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"protobuf",
|
"protobuf",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user