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_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",
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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" }
|
||||
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 ::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>,
|
||||
}
|
||||
|
@ -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/");
|
||||
|
@ -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),
|
||||
}
|
||||
|
@ -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 { "annie2@appflowy.io".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,
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
||||
|
5
shared-lib/Cargo.lock
generated
5
shared-lib/Cargo.lock
generated
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user