浏览代码

config doc sql table

appflowy 3 年之前
父节点
当前提交
4e80b296f8
共有 35 个文件被更改,包括 904 次插入129 次删除
  1. 58 16
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pb.dart
  2. 7 4
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbjson.dart
  3. 72 0
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pb.dart
  4. 7 0
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbenum.dart
  5. 21 0
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbjson.dart
  6. 9 0
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbserver.dart
  7. 1 0
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/protobuf.dart
  8. 29 29
      rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/up.sql
  9. 2 0
      rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/down.sql
  10. 10 0
      rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/up.sql
  11. 13 0
      rust-lib/flowy-database/src/schema.rs
  12. 1 0
      rust-lib/flowy-derive/src/derive_cache/derive_cache.rs
  13. 5 1
      rust-lib/flowy-editor/Cargo.toml
  14. 19 5
      rust-lib/flowy-editor/src/entities/doc/doc_create.rs
  15. 5 0
      rust-lib/flowy-editor/src/entities/doc/doc_modify.rs
  16. 36 0
      rust-lib/flowy-editor/src/entities/doc/doc_query.rs
  17. 3 0
      rust-lib/flowy-editor/src/entities/doc/mod.rs
  18. 12 0
      rust-lib/flowy-editor/src/entities/doc/parser/doc_id.rs
  19. 2 0
      rust-lib/flowy-editor/src/entities/doc/parser/mod.rs
  20. 7 4
      rust-lib/flowy-editor/src/handlers/doc_handler.rs
  21. 4 0
      rust-lib/flowy-editor/src/lib.rs
  22. 11 1
      rust-lib/flowy-editor/src/module.rs
  23. 200 63
      rust-lib/flowy-editor/src/protobuf/model/doc_create.rs
  24. 243 0
      rust-lib/flowy-editor/src/protobuf/model/doc_query.rs
  25. 4 4
      rust-lib/flowy-editor/src/protobuf/model/event.rs
  26. 3 0
      rust-lib/flowy-editor/src/protobuf/model/mod.rs
  27. 5 2
      rust-lib/flowy-editor/src/protobuf/proto/doc_create.proto
  28. 6 0
      rust-lib/flowy-editor/src/protobuf/proto/doc_query.proto
  29. 1 0
      rust-lib/flowy-editor/src/protobuf/proto/event.proto
  30. 40 0
      rust-lib/flowy-editor/src/sql_tables/doc/doc_sql.rs
  31. 61 0
      rust-lib/flowy-editor/src/sql_tables/doc/doc_table.rs
  32. 5 0
      rust-lib/flowy-editor/src/sql_tables/doc/mod.rs
  33. 1 0
      rust-lib/flowy-editor/src/sql_tables/mod.rs
  34. 0 0
      rust-lib/flowy-editor/tests/editor/doc_test.rs
  35. 1 0
      rust-lib/flowy-editor/tests/editor/main.rs

+ 58 - 16
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pb.dart

@@ -11,23 +11,28 @@ import 'package:protobuf/protobuf.dart' as $pb;
 
 class CreateDocRequest extends $pb.GeneratedMessage {
   static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'CreateDocRequest', createEmptyInstance: create)
-    ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewId')
+    ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id')
     ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
+    ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc')
     ..hasRequiredFields = false
   ;
 
   CreateDocRequest._() : super();
   factory CreateDocRequest({
-    $core.String? viewId,
+    $core.String? id,
     $core.String? name,
+    $core.String? desc,
   }) {
     final _result = create();
-    if (viewId != null) {
-      _result.viewId = viewId;
+    if (id != null) {
+      _result.id = id;
     }
     if (name != null) {
       _result.name = name;
     }
+    if (desc != null) {
+      _result.desc = desc;
+    }
     return _result;
   }
   factory CreateDocRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
@@ -52,13 +57,13 @@ class CreateDocRequest extends $pb.GeneratedMessage {
   static CreateDocRequest? _defaultInstance;
 
   @$pb.TagNumber(1)
-  $core.String get viewId => $_getSZ(0);
+  $core.String get id => $_getSZ(0);
   @$pb.TagNumber(1)
-  set viewId($core.String v) { $_setString(0, v); }
+  set id($core.String v) { $_setString(0, v); }
   @$pb.TagNumber(1)
-  $core.bool hasViewId() => $_has(0);
+  $core.bool hasId() => $_has(0);
   @$pb.TagNumber(1)
-  void clearViewId() => clearField(1);
+  void clearId() => clearField(1);
 
   @$pb.TagNumber(2)
   $core.String get name => $_getSZ(1);
@@ -68,13 +73,24 @@ class CreateDocRequest extends $pb.GeneratedMessage {
   $core.bool hasName() => $_has(1);
   @$pb.TagNumber(2)
   void clearName() => clearField(2);
+
+  @$pb.TagNumber(3)
+  $core.String get desc => $_getSZ(2);
+  @$pb.TagNumber(3)
+  set desc($core.String v) { $_setString(2, v); }
+  @$pb.TagNumber(3)
+  $core.bool hasDesc() => $_has(2);
+  @$pb.TagNumber(3)
+  void clearDesc() => clearField(3);
 }
 
 class Doc extends $pb.GeneratedMessage {
   static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Doc', createEmptyInstance: create)
     ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id')
     ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
-    ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewId')
+    ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc')
+    ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'path')
+    ..aOS(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'content')
     ..hasRequiredFields = false
   ;
 
@@ -82,7 +98,9 @@ class Doc extends $pb.GeneratedMessage {
   factory Doc({
     $core.String? id,
     $core.String? name,
-    $core.String? viewId,
+    $core.String? desc,
+    $core.String? path,
+    $core.String? content,
   }) {
     final _result = create();
     if (id != null) {
@@ -91,8 +109,14 @@ class Doc extends $pb.GeneratedMessage {
     if (name != null) {
       _result.name = name;
     }
-    if (viewId != null) {
-      _result.viewId = viewId;
+    if (desc != null) {
+      _result.desc = desc;
+    }
+    if (path != null) {
+      _result.path = path;
+    }
+    if (content != null) {
+      _result.content = content;
     }
     return _result;
   }
@@ -136,12 +160,30 @@ class Doc extends $pb.GeneratedMessage {
   void clearName() => clearField(2);
 
   @$pb.TagNumber(3)
-  $core.String get viewId => $_getSZ(2);
+  $core.String get desc => $_getSZ(2);
   @$pb.TagNumber(3)
-  set viewId($core.String v) { $_setString(2, v); }
+  set desc($core.String v) { $_setString(2, v); }
   @$pb.TagNumber(3)
-  $core.bool hasViewId() => $_has(2);
+  $core.bool hasDesc() => $_has(2);
   @$pb.TagNumber(3)
-  void clearViewId() => clearField(3);
+  void clearDesc() => clearField(3);
+
+  @$pb.TagNumber(4)
+  $core.String get path => $_getSZ(3);
+  @$pb.TagNumber(4)
+  set path($core.String v) { $_setString(3, v); }
+  @$pb.TagNumber(4)
+  $core.bool hasPath() => $_has(3);
+  @$pb.TagNumber(4)
+  void clearPath() => clearField(4);
+
+  @$pb.TagNumber(5)
+  $core.String get content => $_getSZ(4);
+  @$pb.TagNumber(5)
+  set content($core.String v) { $_setString(4, v); }
+  @$pb.TagNumber(5)
+  $core.bool hasContent() => $_has(4);
+  @$pb.TagNumber(5)
+  void clearContent() => clearField(5);
 }
 

+ 7 - 4
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbjson.dart

@@ -12,22 +12,25 @@ import 'dart:typed_data' as $typed_data;
 const CreateDocRequest$json = const {
   '1': 'CreateDocRequest',
   '2': const [
-    const {'1': 'view_id', '3': 1, '4': 1, '5': 9, '10': 'viewId'},
+    const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
     const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
+    const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'},
   ],
 };
 
 /// Descriptor for `CreateDocRequest`. Decode as a `google.protobuf.DescriptorProto`.
-final $typed_data.Uint8List createDocRequestDescriptor = $convert.base64Decode('ChBDcmVhdGVEb2NSZXF1ZXN0EhcKB3ZpZXdfaWQYASABKAlSBnZpZXdJZBISCgRuYW1lGAIgASgJUgRuYW1l');
+final $typed_data.Uint8List createDocRequestDescriptor = $convert.base64Decode('ChBDcmVhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBISCgRuYW1lGAIgASgJUgRuYW1lEhIKBGRlc2MYAyABKAlSBGRlc2M=');
 @$core.Deprecated('Use docDescriptor instead')
 const Doc$json = const {
   '1': 'Doc',
   '2': const [
     const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
     const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
-    const {'1': 'view_id', '3': 3, '4': 1, '5': 9, '10': 'viewId'},
+    const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'},
+    const {'1': 'path', '3': 4, '4': 1, '5': 9, '10': 'path'},
+    const {'1': 'content', '3': 5, '4': 1, '5': 9, '10': 'content'},
   ],
 };
 
 /// Descriptor for `Doc`. Decode as a `google.protobuf.DescriptorProto`.
-final $typed_data.Uint8List docDescriptor = $convert.base64Decode('CgNEb2MSDgoCaWQYASABKAlSAmlkEhIKBG5hbWUYAiABKAlSBG5hbWUSFwoHdmlld19pZBgDIAEoCVIGdmlld0lk');
+final $typed_data.Uint8List docDescriptor = $convert.base64Decode('CgNEb2MSDgoCaWQYASABKAlSAmlkEhIKBG5hbWUYAiABKAlSBG5hbWUSEgoEZGVzYxgDIAEoCVIEZGVzYxISCgRwYXRoGAQgASgJUgRwYXRoEhgKB2NvbnRlbnQYBSABKAlSB2NvbnRlbnQ=');

+ 72 - 0
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pb.dart

@@ -0,0 +1,72 @@
+///
+//  Generated code. Do not modify.
+//  source: doc_query.proto
+//
+// @dart = 2.12
+// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields
+
+import 'dart:core' as $core;
+
+import 'package:protobuf/protobuf.dart' as $pb;
+
+class QueryDocRequest extends $pb.GeneratedMessage {
+  static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'QueryDocRequest', createEmptyInstance: create)
+    ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'docId')
+    ..aOB(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'readContent')
+    ..hasRequiredFields = false
+  ;
+
+  QueryDocRequest._() : super();
+  factory QueryDocRequest({
+    $core.String? docId,
+    $core.bool? readContent,
+  }) {
+    final _result = create();
+    if (docId != null) {
+      _result.docId = docId;
+    }
+    if (readContent != null) {
+      _result.readContent = readContent;
+    }
+    return _result;
+  }
+  factory QueryDocRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
+  factory QueryDocRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
+  @$core.Deprecated(
+  'Using this can add significant overhead to your binary. '
+  'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
+  'Will be removed in next major version')
+  QueryDocRequest clone() => QueryDocRequest()..mergeFromMessage(this);
+  @$core.Deprecated(
+  'Using this can add significant overhead to your binary. '
+  'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
+  'Will be removed in next major version')
+  QueryDocRequest copyWith(void Function(QueryDocRequest) updates) => super.copyWith((message) => updates(message as QueryDocRequest)) as QueryDocRequest; // ignore: deprecated_member_use
+  $pb.BuilderInfo get info_ => _i;
+  @$core.pragma('dart2js:noInline')
+  static QueryDocRequest create() => QueryDocRequest._();
+  QueryDocRequest createEmptyInstance() => create();
+  static $pb.PbList<QueryDocRequest> createRepeated() => $pb.PbList<QueryDocRequest>();
+  @$core.pragma('dart2js:noInline')
+  static QueryDocRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<QueryDocRequest>(create);
+  static QueryDocRequest? _defaultInstance;
+
+  @$pb.TagNumber(1)
+  $core.String get docId => $_getSZ(0);
+  @$pb.TagNumber(1)
+  set docId($core.String v) { $_setString(0, v); }
+  @$pb.TagNumber(1)
+  $core.bool hasDocId() => $_has(0);
+  @$pb.TagNumber(1)
+  void clearDocId() => clearField(1);
+
+  @$pb.TagNumber(2)
+  $core.bool get readContent => $_getBF(1);
+  @$pb.TagNumber(2)
+  set readContent($core.bool v) { $_setBool(1, v); }
+  @$pb.TagNumber(2)
+  $core.bool hasReadContent() => $_has(1);
+  @$pb.TagNumber(2)
+  void clearReadContent() => clearField(2);
+}
+

+ 7 - 0
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbenum.dart

@@ -0,0 +1,7 @@
+///
+//  Generated code. Do not modify.
+//  source: doc_query.proto
+//
+// @dart = 2.12
+// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields
+

+ 21 - 0
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbjson.dart

@@ -0,0 +1,21 @@
+///
+//  Generated code. Do not modify.
+//  source: doc_query.proto
+//
+// @dart = 2.12
+// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package
+
+import 'dart:core' as $core;
+import 'dart:convert' as $convert;
+import 'dart:typed_data' as $typed_data;
+@$core.Deprecated('Use queryDocRequestDescriptor instead')
+const QueryDocRequest$json = const {
+  '1': 'QueryDocRequest',
+  '2': const [
+    const {'1': 'doc_id', '3': 1, '4': 1, '5': 9, '10': 'docId'},
+    const {'1': 'read_content', '3': 2, '4': 1, '5': 8, '10': 'readContent'},
+  ],
+};
+
+/// Descriptor for `QueryDocRequest`. Decode as a `google.protobuf.DescriptorProto`.
+final $typed_data.Uint8List queryDocRequestDescriptor = $convert.base64Decode('Cg9RdWVyeURvY1JlcXVlc3QSFQoGZG9jX2lkGAEgASgJUgVkb2NJZBIhCgxyZWFkX2NvbnRlbnQYAiABKAhSC3JlYWRDb250ZW50');

+ 9 - 0
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_query.pbserver.dart

@@ -0,0 +1,9 @@
+///
+//  Generated code. Do not modify.
+//  source: doc_query.proto
+//
+// @dart = 2.12
+// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package
+
+export 'doc_query.pb.dart';
+

+ 1 - 0
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/protobuf.dart

@@ -2,3 +2,4 @@
 export './doc_create.pb.dart';
 export './errors.pb.dart';
 export './event.pb.dart';
+export './doc_query.pb.dart';

+ 29 - 29
rust-lib/flowy-database/migrations/2021-07-09-063045_flowy-user/up.sql

@@ -1,42 +1,42 @@
 -- Your SQL goes here
 
 CREATE TABLE user_table (
-        id TEXT NOT NULL PRIMARY KEY,
-        name TEXT NOT NULL DEFAULT '',
-        password TEXT NOT NULL DEFAULT '',
-        email TEXT NOT NULL DEFAULT ''
+    id TEXT NOT NULL PRIMARY KEY,
+    name TEXT NOT NULL DEFAULT '',
+    password TEXT NOT NULL DEFAULT '',
+    email TEXT NOT NULL DEFAULT ''
 );
 
 CREATE TABLE workspace_table (
-                                 id TEXT NOT NULL PRIMARY KEY,
-                                 name TEXT NOT NULL DEFAULT '',
-                                 desc TEXT NOT NULL DEFAULT '',
-                                 modified_time BIGINT NOT NULL DEFAULT 0,
-                                 create_time BIGINT NOT NULL DEFAULT 0,
-                                 user_id TEXT NOT NULL DEFAULT '',
-                                 version BIGINT NOT NULL DEFAULT 0
+    id TEXT NOT NULL PRIMARY KEY,
+    name TEXT NOT NULL DEFAULT '',
+    desc TEXT NOT NULL DEFAULT '',
+    modified_time BIGINT NOT NULL DEFAULT 0,
+    create_time BIGINT NOT NULL DEFAULT 0,
+    user_id TEXT NOT NULL DEFAULT '',
+    version BIGINT NOT NULL DEFAULT 0
 );
 
 CREATE TABLE app_table (
-                           id TEXT NOT NULL PRIMARY KEY,
-                           workspace_id TEXT NOT NULL DEFAULT '',
-                           name TEXT NOT NULL DEFAULT '',
-                           desc TEXT NOT NULL DEFAULT '',
-                           color_style BLOB NOT NULL DEFAULT (x''),
-                           last_view_id TEXT DEFAULT '',
-                           modified_time BIGINT NOT NULL DEFAULT 0,
-                           create_time BIGINT NOT NULL DEFAULT 0,
-                           version BIGINT NOT NULL DEFAULT 0
+    id TEXT NOT NULL PRIMARY KEY,
+    workspace_id TEXT NOT NULL DEFAULT '',
+    name TEXT NOT NULL DEFAULT '',
+    desc TEXT NOT NULL DEFAULT '',
+    color_style BLOB NOT NULL DEFAULT (x''),
+    last_view_id TEXT DEFAULT '',
+    modified_time BIGINT NOT NULL DEFAULT 0,
+    create_time BIGINT NOT NULL DEFAULT 0,
+    version BIGINT NOT NULL DEFAULT 0
 );
 
 CREATE TABLE view_table (
-                            id TEXT NOT NULL PRIMARY KEY,
-                            app_id TEXT NOT NULL DEFAULT '',
-                            name TEXT NOT NULL DEFAULT '',
-                            desc TEXT NOT NULL DEFAULT '',
-                            modified_time BIGINT NOT NULL DEFAULT 0,
-                            create_time BIGINT NOT NULL DEFAULT 0,
-                            thumbnail TEXT NOT NULL DEFAULT '',
-                            view_type INTEGER NOT NULL DEFAULT 0,
-                            version BIGINT NOT NULL DEFAULT 0
+    id TEXT NOT NULL PRIMARY KEY,
+    app_id TEXT NOT NULL DEFAULT '',
+    name TEXT NOT NULL DEFAULT '',
+    desc TEXT NOT NULL DEFAULT '',
+    modified_time BIGINT NOT NULL DEFAULT 0,
+    create_time BIGINT NOT NULL DEFAULT 0,
+    thumbnail TEXT NOT NULL DEFAULT '',
+    view_type INTEGER NOT NULL DEFAULT 0,
+    version BIGINT NOT NULL DEFAULT 0
 );

+ 2 - 0
rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/down.sql

@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+DROP TABLE doc_table;

+ 10 - 0
rust-lib/flowy-database/migrations/2021-07-22-234458_flowy-editor/up.sql

@@ -0,0 +1,10 @@
+-- Your SQL goes here
+CREATE TABLE doc_table (
+    id TEXT NOT NULL PRIMARY KEY,
+    name TEXT NOT NULL DEFAULT '',
+    desc TEXT NOT NULL DEFAULT '',
+    path TEXT NOT NULL DEFAULT '',
+    modified_time BIGINT NOT NULL DEFAULT 0,
+    create_time BIGINT NOT NULL DEFAULT 0,
+    version BIGINT NOT NULL DEFAULT 0
+);

+ 13 - 0
rust-lib/flowy-database/src/schema.rs

@@ -12,6 +12,18 @@ table! {
     }
 }
 
+table! {
+    doc_table (id) {
+        id -> Text,
+        name -> Text,
+        desc -> Text,
+        path -> Text,
+        modified_time -> BigInt,
+        create_time -> BigInt,
+        version -> BigInt,
+    }
+}
+
 table! {
     user_table (id) {
         id -> Text,
@@ -50,6 +62,7 @@ table! {
 
 allow_tables_to_appear_in_same_query!(
     app_table,
+    doc_table,
     user_table,
     view_table,
     workspace_table,

+ 1 - 0
rust-lib/flowy-derive/src/derive_cache/derive_cache.rs

@@ -19,6 +19,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
         | "KeyValue"
         | "CreateDocRequest"
         | "Doc"
+        | "QueryDocRequest"
         | "EditorError"
         | "QueryAppRequest"
         | "CreateAppRequest"

+ 5 - 1
rust-lib/flowy-editor/Cargo.toml

@@ -11,6 +11,10 @@ flowy-dispatch = { path = "../flowy-dispatch" }
 flowy-log = { path = "../flowy-log" }
 flowy-derive = { path = "../flowy-derive" }
 flowy-database = { path = "../flowy-database" }
+flowy-infra = { path = "../flowy-infra" }
 diesel = {version = "1.4.7", features = ["sqlite"]}
 diesel_derives = {version = "1.4.1", features = ["sqlite"]}
-protobuf = {version = "2.18.0"}
+protobuf = {version = "2.18.0"}
+
+[dev-dependencies]
+flowy-test = { path = "../flowy-test" }

+ 19 - 5
rust-lib/flowy-editor/src/entities/doc/doc_create.rs

@@ -8,15 +8,19 @@ use std::convert::TryInto;
 #[derive(ProtoBuf, Default)]
 pub struct CreateDocRequest {
     #[pb(index = 1)]
-    view_id: String,
+    id: String,
 
     #[pb(index = 2)]
     pub name: String,
+
+    #[pb(index = 3)]
+    pub desc: String,
 }
 
 pub struct CreateDocParams {
-    pub view_id: String,
+    pub id: String,
     pub name: String,
+    pub desc: String,
 }
 
 impl TryInto<CreateDocParams> for CreateDocRequest {
@@ -31,7 +35,7 @@ impl TryInto<CreateDocParams> for CreateDocRequest {
             })?
             .0;
 
-        let view_id = DocViewId::parse(self.view_id)
+        let id = DocViewId::parse(self.id)
             .map_err(|e| {
                 ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid)
                     .msg(e)
@@ -39,7 +43,11 @@ impl TryInto<CreateDocParams> for CreateDocRequest {
             })?
             .0;
 
-        Ok(CreateDocParams { view_id, name })
+        Ok(CreateDocParams {
+            id,
+            name,
+            desc: self.desc,
+        })
     }
 }
 
@@ -52,5 +60,11 @@ pub struct Doc {
     pub name: String,
 
     #[pb(index = 3)]
-    pub view_id: String,
+    pub desc: String,
+
+    #[pb(index = 4)]
+    pub path: String,
+
+    #[pb(index = 5)]
+    pub content: String,
 }

+ 5 - 0
rust-lib/flowy-editor/src/entities/doc/doc_modify.rs

@@ -0,0 +1,5 @@
+pub(crate) struct UpdateDocParams {
+    pub(crate) id: String,
+    pub(crate) name: Option<String>,
+    pub(crate) desc: Option<String>,
+}

+ 36 - 0
rust-lib/flowy-editor/src/entities/doc/doc_query.rs

@@ -0,0 +1,36 @@
+use crate::{entities::doc::parser::DocId, errors::*};
+use flowy_derive::ProtoBuf;
+use std::convert::TryInto;
+
+#[derive(Default, ProtoBuf)]
+pub struct QueryDocRequest {
+    #[pb(index = 1)]
+    pub doc_id: String,
+
+    #[pb(index = 2)]
+    pub read_content: bool,
+}
+
+pub struct QueryDocParams {
+    pub doc_id: String,
+    pub read_content: bool,
+}
+
+impl TryInto<QueryDocParams> for QueryDocRequest {
+    type Error = EditorError;
+
+    fn try_into(self) -> Result<QueryDocParams, Self::Error> {
+        let doc_id = DocId::parse(self.doc_id)
+            .map_err(|e| {
+                ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid)
+                    .msg(e)
+                    .build()
+            })?
+            .0;
+
+        Ok(QueryDocParams {
+            doc_id,
+            read_content: self.read_content,
+        })
+    }
+}

+ 3 - 0
rust-lib/flowy-editor/src/entities/doc/mod.rs

@@ -1,5 +1,8 @@
 mod doc_create;
 mod doc_modify;
+mod doc_query;
 mod parser;
 
 pub use doc_create::*;
+pub use doc_modify::*;
+pub use doc_query::*;

+ 12 - 0
rust-lib/flowy-editor/src/entities/doc/parser/doc_id.rs

@@ -0,0 +1,12 @@
+#[derive(Debug)]
+pub struct DocId(pub String);
+
+impl DocId {
+    pub fn parse(s: String) -> Result<DocId, String> {
+        if s.trim().is_empty() {
+            return Err(format!("Doc id can not be empty or whitespace"));
+        }
+
+        Ok(Self(s))
+    }
+}

+ 2 - 0
rust-lib/flowy-editor/src/entities/doc/parser/mod.rs

@@ -1,5 +1,7 @@
+mod doc_id;
 mod doc_name;
 mod doc_view_id;
 
+pub use doc_id::*;
 pub use doc_name::*;
 pub use doc_view_id::*;

+ 7 - 4
rust-lib/flowy-editor/src/handlers/doc_handler.rs

@@ -1,12 +1,15 @@
-use crate::{entities::doc::*, errors::EditorError};
+use crate::{entities::doc::*, errors::EditorError, services::file_manager::FileManager};
 use flowy_dispatch::prelude::*;
-use std::{convert::TryInto, sync::Arc};
+use std::{
+    convert::TryInto,
+    sync::{Arc, RwLock},
+};
 
 pub async fn create_doc(
     data: Data<CreateDocRequest>,
-    // session: ModuleData<Arc<UserSession>>,
+    manager: ModuleData<RwLock<FileManager>>,
 ) -> ResponseResult<Doc, EditorError> {
-    // let params: SignInParams = data.into_inner().try_into()?;
+    let params: CreateDocParams = data.into_inner().try_into()?;
     // let user = session.sign_in(params).await?;
     // let user_detail = UserDetail::from(user);
     // response_ok(user_detail)

+ 4 - 0
rust-lib/flowy-editor/src/lib.rs

@@ -5,6 +5,10 @@ mod handlers;
 pub mod module;
 mod protobuf;
 mod services;
+mod sql_tables;
+
+#[macro_use]
+extern crate flowy_database;
 
 pub mod prelude {
     pub use crate::module::*;

+ 11 - 1
rust-lib/flowy-editor/src/module.rs

@@ -1,7 +1,17 @@
-use crate::{event::EditorEvent, handlers::*, services::file_manager::FileManager};
+use crate::{
+    errors::EditorError,
+    event::EditorEvent,
+    handlers::*,
+    services::file_manager::FileManager,
+};
+use flowy_database::DBConnection;
 use flowy_dispatch::prelude::*;
 use std::sync::{Arc, RwLock};
 
+pub trait EditorDatabase: Send + Sync {
+    fn db_connection(&self) -> Result<DBConnection, EditorError>;
+}
+
 pub fn create() -> Module {
     let file_manager = RwLock::new(FileManager::new());
 

+ 200 - 63
rust-lib/flowy-editor/src/protobuf/model/doc_create.rs

@@ -26,8 +26,9 @@
 #[derive(PartialEq,Clone,Default)]
 pub struct CreateDocRequest {
     // message fields
-    pub view_id: ::std::string::String,
+    pub id: ::std::string::String,
     pub name: ::std::string::String,
+    pub desc: ::std::string::String,
     // special fields
     pub unknown_fields: ::protobuf::UnknownFields,
     pub cached_size: ::protobuf::CachedSize,
@@ -44,30 +45,30 @@ impl CreateDocRequest {
         ::std::default::Default::default()
     }
 
-    // string view_id = 1;
+    // string id = 1;
 
 
-    pub fn get_view_id(&self) -> &str {
-        &self.view_id
+    pub fn get_id(&self) -> &str {
+        &self.id
     }
-    pub fn clear_view_id(&mut self) {
-        self.view_id.clear();
+    pub fn clear_id(&mut self) {
+        self.id.clear();
     }
 
     // Param is passed by value, moved
-    pub fn set_view_id(&mut self, v: ::std::string::String) {
-        self.view_id = v;
+    pub fn set_id(&mut self, v: ::std::string::String) {
+        self.id = v;
     }
 
     // Mutable pointer to the field.
     // If field is not initialized, it is initialized with default value first.
-    pub fn mut_view_id(&mut self) -> &mut ::std::string::String {
-        &mut self.view_id
+    pub fn mut_id(&mut self) -> &mut ::std::string::String {
+        &mut self.id
     }
 
     // Take field
-    pub fn take_view_id(&mut self) -> ::std::string::String {
-        ::std::mem::replace(&mut self.view_id, ::std::string::String::new())
+    pub fn take_id(&mut self) -> ::std::string::String {
+        ::std::mem::replace(&mut self.id, ::std::string::String::new())
     }
 
     // string name = 2;
@@ -95,6 +96,32 @@ impl CreateDocRequest {
     pub fn take_name(&mut self) -> ::std::string::String {
         ::std::mem::replace(&mut self.name, ::std::string::String::new())
     }
+
+    // string desc = 3;
+
+
+    pub fn get_desc(&self) -> &str {
+        &self.desc
+    }
+    pub fn clear_desc(&mut self) {
+        self.desc.clear();
+    }
+
+    // Param is passed by value, moved
+    pub fn set_desc(&mut self, v: ::std::string::String) {
+        self.desc = v;
+    }
+
+    // Mutable pointer to the field.
+    // If field is not initialized, it is initialized with default value first.
+    pub fn mut_desc(&mut self) -> &mut ::std::string::String {
+        &mut self.desc
+    }
+
+    // Take field
+    pub fn take_desc(&mut self) -> ::std::string::String {
+        ::std::mem::replace(&mut self.desc, ::std::string::String::new())
+    }
 }
 
 impl ::protobuf::Message for CreateDocRequest {
@@ -107,11 +134,14 @@ impl ::protobuf::Message for CreateDocRequest {
             let (field_number, wire_type) = is.read_tag_unpack()?;
             match field_number {
                 1 => {
-                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.view_id)?;
+                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.id)?;
                 },
                 2 => {
                     ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?;
                 },
+                3 => {
+                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?;
+                },
                 _ => {
                     ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
                 },
@@ -124,24 +154,30 @@ impl ::protobuf::Message for CreateDocRequest {
     #[allow(unused_variables)]
     fn compute_size(&self) -> u32 {
         let mut my_size = 0;
-        if !self.view_id.is_empty() {
-            my_size += ::protobuf::rt::string_size(1, &self.view_id);
+        if !self.id.is_empty() {
+            my_size += ::protobuf::rt::string_size(1, &self.id);
         }
         if !self.name.is_empty() {
             my_size += ::protobuf::rt::string_size(2, &self.name);
         }
+        if !self.desc.is_empty() {
+            my_size += ::protobuf::rt::string_size(3, &self.desc);
+        }
         my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
         self.cached_size.set(my_size);
         my_size
     }
 
     fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
-        if !self.view_id.is_empty() {
-            os.write_string(1, &self.view_id)?;
+        if !self.id.is_empty() {
+            os.write_string(1, &self.id)?;
         }
         if !self.name.is_empty() {
             os.write_string(2, &self.name)?;
         }
+        if !self.desc.is_empty() {
+            os.write_string(3, &self.desc)?;
+        }
         os.write_unknown_fields(self.get_unknown_fields())?;
         ::std::result::Result::Ok(())
     }
@@ -181,15 +217,20 @@ impl ::protobuf::Message for CreateDocRequest {
         descriptor.get(|| {
             let mut fields = ::std::vec::Vec::new();
             fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
-                "view_id",
-                |m: &CreateDocRequest| { &m.view_id },
-                |m: &mut CreateDocRequest| { &mut m.view_id },
+                "id",
+                |m: &CreateDocRequest| { &m.id },
+                |m: &mut CreateDocRequest| { &mut m.id },
             ));
             fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
                 "name",
                 |m: &CreateDocRequest| { &m.name },
                 |m: &mut CreateDocRequest| { &mut m.name },
             ));
+            fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
+                "desc",
+                |m: &CreateDocRequest| { &m.desc },
+                |m: &mut CreateDocRequest| { &mut m.desc },
+            ));
             ::protobuf::reflect::MessageDescriptor::new_pb_name::<CreateDocRequest>(
                 "CreateDocRequest",
                 fields,
@@ -206,8 +247,9 @@ impl ::protobuf::Message for CreateDocRequest {
 
 impl ::protobuf::Clear for CreateDocRequest {
     fn clear(&mut self) {
-        self.view_id.clear();
+        self.id.clear();
         self.name.clear();
+        self.desc.clear();
         self.unknown_fields.clear();
     }
 }
@@ -229,7 +271,9 @@ pub struct Doc {
     // message fields
     pub id: ::std::string::String,
     pub name: ::std::string::String,
-    pub view_id: ::std::string::String,
+    pub desc: ::std::string::String,
+    pub path: ::std::string::String,
+    pub content: ::std::string::String,
     // special fields
     pub unknown_fields: ::protobuf::UnknownFields,
     pub cached_size: ::protobuf::CachedSize,
@@ -298,30 +342,82 @@ impl Doc {
         ::std::mem::replace(&mut self.name, ::std::string::String::new())
     }
 
-    // string view_id = 3;
+    // string desc = 3;
 
 
-    pub fn get_view_id(&self) -> &str {
-        &self.view_id
+    pub fn get_desc(&self) -> &str {
+        &self.desc
     }
-    pub fn clear_view_id(&mut self) {
-        self.view_id.clear();
+    pub fn clear_desc(&mut self) {
+        self.desc.clear();
     }
 
     // Param is passed by value, moved
-    pub fn set_view_id(&mut self, v: ::std::string::String) {
-        self.view_id = v;
+    pub fn set_desc(&mut self, v: ::std::string::String) {
+        self.desc = v;
     }
 
     // Mutable pointer to the field.
     // If field is not initialized, it is initialized with default value first.
-    pub fn mut_view_id(&mut self) -> &mut ::std::string::String {
-        &mut self.view_id
+    pub fn mut_desc(&mut self) -> &mut ::std::string::String {
+        &mut self.desc
     }
 
     // Take field
-    pub fn take_view_id(&mut self) -> ::std::string::String {
-        ::std::mem::replace(&mut self.view_id, ::std::string::String::new())
+    pub fn take_desc(&mut self) -> ::std::string::String {
+        ::std::mem::replace(&mut self.desc, ::std::string::String::new())
+    }
+
+    // string path = 4;
+
+
+    pub fn get_path(&self) -> &str {
+        &self.path
+    }
+    pub fn clear_path(&mut self) {
+        self.path.clear();
+    }
+
+    // Param is passed by value, moved
+    pub fn set_path(&mut self, v: ::std::string::String) {
+        self.path = v;
+    }
+
+    // Mutable pointer to the field.
+    // If field is not initialized, it is initialized with default value first.
+    pub fn mut_path(&mut self) -> &mut ::std::string::String {
+        &mut self.path
+    }
+
+    // Take field
+    pub fn take_path(&mut self) -> ::std::string::String {
+        ::std::mem::replace(&mut self.path, ::std::string::String::new())
+    }
+
+    // string content = 5;
+
+
+    pub fn get_content(&self) -> &str {
+        &self.content
+    }
+    pub fn clear_content(&mut self) {
+        self.content.clear();
+    }
+
+    // Param is passed by value, moved
+    pub fn set_content(&mut self, v: ::std::string::String) {
+        self.content = v;
+    }
+
+    // Mutable pointer to the field.
+    // If field is not initialized, it is initialized with default value first.
+    pub fn mut_content(&mut self) -> &mut ::std::string::String {
+        &mut self.content
+    }
+
+    // Take field
+    pub fn take_content(&mut self) -> ::std::string::String {
+        ::std::mem::replace(&mut self.content, ::std::string::String::new())
     }
 }
 
@@ -341,7 +437,13 @@ impl ::protobuf::Message for Doc {
                     ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?;
                 },
                 3 => {
-                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.view_id)?;
+                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?;
+                },
+                4 => {
+                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.path)?;
+                },
+                5 => {
+                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.content)?;
                 },
                 _ => {
                     ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
@@ -361,8 +463,14 @@ impl ::protobuf::Message for Doc {
         if !self.name.is_empty() {
             my_size += ::protobuf::rt::string_size(2, &self.name);
         }
-        if !self.view_id.is_empty() {
-            my_size += ::protobuf::rt::string_size(3, &self.view_id);
+        if !self.desc.is_empty() {
+            my_size += ::protobuf::rt::string_size(3, &self.desc);
+        }
+        if !self.path.is_empty() {
+            my_size += ::protobuf::rt::string_size(4, &self.path);
+        }
+        if !self.content.is_empty() {
+            my_size += ::protobuf::rt::string_size(5, &self.content);
         }
         my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
         self.cached_size.set(my_size);
@@ -376,8 +484,14 @@ impl ::protobuf::Message for Doc {
         if !self.name.is_empty() {
             os.write_string(2, &self.name)?;
         }
-        if !self.view_id.is_empty() {
-            os.write_string(3, &self.view_id)?;
+        if !self.desc.is_empty() {
+            os.write_string(3, &self.desc)?;
+        }
+        if !self.path.is_empty() {
+            os.write_string(4, &self.path)?;
+        }
+        if !self.content.is_empty() {
+            os.write_string(5, &self.content)?;
         }
         os.write_unknown_fields(self.get_unknown_fields())?;
         ::std::result::Result::Ok(())
@@ -428,9 +542,19 @@ impl ::protobuf::Message for Doc {
                 |m: &mut Doc| { &mut m.name },
             ));
             fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
-                "view_id",
-                |m: &Doc| { &m.view_id },
-                |m: &mut Doc| { &mut m.view_id },
+                "desc",
+                |m: &Doc| { &m.desc },
+                |m: &mut Doc| { &mut m.desc },
+            ));
+            fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
+                "path",
+                |m: &Doc| { &m.path },
+                |m: &mut Doc| { &mut m.path },
+            ));
+            fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
+                "content",
+                |m: &Doc| { &m.content },
+                |m: &mut Doc| { &mut m.content },
             ));
             ::protobuf::reflect::MessageDescriptor::new_pb_name::<Doc>(
                 "Doc",
@@ -450,7 +574,9 @@ impl ::protobuf::Clear for Doc {
     fn clear(&mut self) {
         self.id.clear();
         self.name.clear();
-        self.view_id.clear();
+        self.desc.clear();
+        self.path.clear();
+        self.content.clear();
         self.unknown_fields.clear();
     }
 }
@@ -468,27 +594,38 @@ impl ::protobuf::reflect::ProtobufValue for Doc {
 }
 
 static file_descriptor_proto_data: &'static [u8] = b"\
-    \n\x10doc_create.proto\"?\n\x10CreateDocRequest\x12\x17\n\x07view_id\x18\
-    \x01\x20\x01(\tR\x06viewId\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\
-    \"B\n\x03Doc\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02id\x12\x12\n\x04name\
-    \x18\x02\x20\x01(\tR\x04name\x12\x17\n\x07view_id\x18\x03\x20\x01(\tR\
-    \x06viewIdJ\xd5\x02\n\x06\x12\x04\0\0\n\x01\n\x08\n\x01\x0c\x12\x03\0\0\
-    \x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\
-    \x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x17\n\x0c\n\x05\x04\
-    \0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\
-    \x0b\x12\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x15\x16\n\x0b\n\x04\x04\
-    \0\x02\x01\x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\
-    \x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\
-    \0\x02\x01\x03\x12\x03\x04\x12\x13\n\n\n\x02\x04\x01\x12\x04\x06\0\n\x01\
-    \n\n\n\x03\x04\x01\x01\x12\x03\x06\x08\x0b\n\x0b\n\x04\x04\x01\x02\0\x12\
-    \x03\x07\x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x07\x04\n\n\x0c\n\
-    \x05\x04\x01\x02\0\x01\x12\x03\x07\x0b\r\n\x0c\n\x05\x04\x01\x02\0\x03\
-    \x12\x03\x07\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x08\x04\x14\n\
-    \x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\
-    \x01\x01\x12\x03\x08\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x08\
-    \x12\x13\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\t\x04\x17\n\x0c\n\x05\x04\
-    \x01\x02\x02\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\
-    \t\x0b\x12\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\t\x15\x16b\x06proto3\
+    \n\x10doc_create.proto\"J\n\x10CreateDocRequest\x12\x0e\n\x02id\x18\x01\
+    \x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\
+    \n\x04desc\x18\x03\x20\x01(\tR\x04desc\"k\n\x03Doc\x12\x0e\n\x02id\x18\
+    \x01\x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\
+    \x12\n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12\x12\n\x04path\x18\x04\x20\
+    \x01(\tR\x04path\x12\x18\n\x07content\x18\x05\x20\x01(\tR\x07contentJ\
+    \xfa\x03\n\x06\x12\x04\0\0\r\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\
+    \x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x18\
+    \n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x04\0\x02\0\x05\
+    \x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\r\n\x0c\n\
+    \x05\x04\0\x02\0\x03\x12\x03\x03\x10\x11\n\x0b\n\x04\x04\0\x02\x01\x12\
+    \x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\
+    \x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\
+    \x12\x03\x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\
+    \n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\
+    \x12\x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\
+    \n\n\x02\x04\x01\x12\x04\x07\0\r\x01\n\n\n\x03\x04\x01\x01\x12\x03\x07\
+    \x08\x0b\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x08\x04\x12\n\x0c\n\x05\x04\
+    \x01\x02\0\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\
+    \x08\x0b\r\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x08\x10\x11\n\x0b\n\x04\
+    \x04\x01\x02\x01\x12\x03\t\x04\x14\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\
+    \x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\t\x0b\x0f\n\x0c\n\
+    \x05\x04\x01\x02\x01\x03\x12\x03\t\x12\x13\n\x0b\n\x04\x04\x01\x02\x02\
+    \x12\x03\n\x04\x14\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\n\x04\n\n\x0c\
+    \n\x05\x04\x01\x02\x02\x01\x12\x03\n\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x02\
+    \x03\x12\x03\n\x12\x13\n\x0b\n\x04\x04\x01\x02\x03\x12\x03\x0b\x04\x14\n\
+    \x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\x0b\x04\n\n\x0c\n\x05\x04\x01\x02\
+    \x03\x01\x12\x03\x0b\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x03\x03\x12\x03\x0b\
+    \x12\x13\n\x0b\n\x04\x04\x01\x02\x04\x12\x03\x0c\x04\x17\n\x0c\n\x05\x04\
+    \x01\x02\x04\x05\x12\x03\x0c\x04\n\n\x0c\n\x05\x04\x01\x02\x04\x01\x12\
+    \x03\x0c\x0b\x12\n\x0c\n\x05\x04\x01\x02\x04\x03\x12\x03\x0c\x15\x16b\
+    \x06proto3\
 ";
 
 static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

+ 243 - 0
rust-lib/flowy-editor/src/protobuf/model/doc_query.rs

@@ -0,0 +1,243 @@
+// This file is generated by rust-protobuf 2.22.1. Do not edit
+// @generated
+
+// https://github.com/rust-lang/rust-clippy/issues/702
+#![allow(unknown_lints)]
+#![allow(clippy::all)]
+
+#![allow(unused_attributes)]
+#![cfg_attr(rustfmt, rustfmt::skip)]
+
+#![allow(box_pointers)]
+#![allow(dead_code)]
+#![allow(missing_docs)]
+#![allow(non_camel_case_types)]
+#![allow(non_snake_case)]
+#![allow(non_upper_case_globals)]
+#![allow(trivial_casts)]
+#![allow(unused_imports)]
+#![allow(unused_results)]
+//! Generated file from `doc_query.proto`
+
+/// Generated files are compatible only with the same version
+/// of protobuf runtime.
+// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1;
+
+#[derive(PartialEq,Clone,Default)]
+pub struct QueryDocRequest {
+    // message fields
+    pub doc_id: ::std::string::String,
+    pub read_content: bool,
+    // special fields
+    pub unknown_fields: ::protobuf::UnknownFields,
+    pub cached_size: ::protobuf::CachedSize,
+}
+
+impl<'a> ::std::default::Default for &'a QueryDocRequest {
+    fn default() -> &'a QueryDocRequest {
+        <QueryDocRequest as ::protobuf::Message>::default_instance()
+    }
+}
+
+impl QueryDocRequest {
+    pub fn new() -> QueryDocRequest {
+        ::std::default::Default::default()
+    }
+
+    // string doc_id = 1;
+
+
+    pub fn get_doc_id(&self) -> &str {
+        &self.doc_id
+    }
+    pub fn clear_doc_id(&mut self) {
+        self.doc_id.clear();
+    }
+
+    // Param is passed by value, moved
+    pub fn set_doc_id(&mut self, v: ::std::string::String) {
+        self.doc_id = v;
+    }
+
+    // Mutable pointer to the field.
+    // If field is not initialized, it is initialized with default value first.
+    pub fn mut_doc_id(&mut self) -> &mut ::std::string::String {
+        &mut self.doc_id
+    }
+
+    // Take field
+    pub fn take_doc_id(&mut self) -> ::std::string::String {
+        ::std::mem::replace(&mut self.doc_id, ::std::string::String::new())
+    }
+
+    // bool read_content = 2;
+
+
+    pub fn get_read_content(&self) -> bool {
+        self.read_content
+    }
+    pub fn clear_read_content(&mut self) {
+        self.read_content = false;
+    }
+
+    // Param is passed by value, moved
+    pub fn set_read_content(&mut self, v: bool) {
+        self.read_content = v;
+    }
+}
+
+impl ::protobuf::Message for QueryDocRequest {
+    fn is_initialized(&self) -> bool {
+        true
+    }
+
+    fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
+        while !is.eof()? {
+            let (field_number, wire_type) = is.read_tag_unpack()?;
+            match field_number {
+                1 => {
+                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.doc_id)?;
+                },
+                2 => {
+                    if wire_type != ::protobuf::wire_format::WireTypeVarint {
+                        return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
+                    }
+                    let tmp = is.read_bool()?;
+                    self.read_content = tmp;
+                },
+                _ => {
+                    ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
+                },
+            };
+        }
+        ::std::result::Result::Ok(())
+    }
+
+    // Compute sizes of nested messages
+    #[allow(unused_variables)]
+    fn compute_size(&self) -> u32 {
+        let mut my_size = 0;
+        if !self.doc_id.is_empty() {
+            my_size += ::protobuf::rt::string_size(1, &self.doc_id);
+        }
+        if self.read_content != false {
+            my_size += 2;
+        }
+        my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
+        self.cached_size.set(my_size);
+        my_size
+    }
+
+    fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
+        if !self.doc_id.is_empty() {
+            os.write_string(1, &self.doc_id)?;
+        }
+        if self.read_content != false {
+            os.write_bool(2, self.read_content)?;
+        }
+        os.write_unknown_fields(self.get_unknown_fields())?;
+        ::std::result::Result::Ok(())
+    }
+
+    fn get_cached_size(&self) -> u32 {
+        self.cached_size.get()
+    }
+
+    fn get_unknown_fields(&self) -> &::protobuf::UnknownFields {
+        &self.unknown_fields
+    }
+
+    fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields {
+        &mut self.unknown_fields
+    }
+
+    fn as_any(&self) -> &dyn (::std::any::Any) {
+        self as &dyn (::std::any::Any)
+    }
+    fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
+        self as &mut dyn (::std::any::Any)
+    }
+    fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
+        self
+    }
+
+    fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
+        Self::descriptor_static()
+    }
+
+    fn new() -> QueryDocRequest {
+        QueryDocRequest::new()
+    }
+
+    fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
+        static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT;
+        descriptor.get(|| {
+            let mut fields = ::std::vec::Vec::new();
+            fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
+                "doc_id",
+                |m: &QueryDocRequest| { &m.doc_id },
+                |m: &mut QueryDocRequest| { &mut m.doc_id },
+            ));
+            fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>(
+                "read_content",
+                |m: &QueryDocRequest| { &m.read_content },
+                |m: &mut QueryDocRequest| { &mut m.read_content },
+            ));
+            ::protobuf::reflect::MessageDescriptor::new_pb_name::<QueryDocRequest>(
+                "QueryDocRequest",
+                fields,
+                file_descriptor_proto()
+            )
+        })
+    }
+
+    fn default_instance() -> &'static QueryDocRequest {
+        static instance: ::protobuf::rt::LazyV2<QueryDocRequest> = ::protobuf::rt::LazyV2::INIT;
+        instance.get(QueryDocRequest::new)
+    }
+}
+
+impl ::protobuf::Clear for QueryDocRequest {
+    fn clear(&mut self) {
+        self.doc_id.clear();
+        self.read_content = false;
+        self.unknown_fields.clear();
+    }
+}
+
+impl ::std::fmt::Debug for QueryDocRequest {
+    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
+        ::protobuf::text_format::fmt(self, f)
+    }
+}
+
+impl ::protobuf::reflect::ProtobufValue for QueryDocRequest {
+    fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
+        ::protobuf::reflect::ReflectValueRef::Message(self)
+    }
+}
+
+static file_descriptor_proto_data: &'static [u8] = b"\
+    \n\x0fdoc_query.proto\"K\n\x0fQueryDocRequest\x12\x15\n\x06doc_id\x18\
+    \x01\x20\x01(\tR\x05docId\x12!\n\x0cread_content\x18\x02\x20\x01(\x08R\
+    \x0breadContentJ\x98\x01\n\x06\x12\x04\0\0\x05\x01\n\x08\n\x01\x0c\x12\
+    \x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\
+    \x12\x03\x02\x08\x17\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x16\n\x0c\n\
+    \x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\
+    \x03\x03\x0b\x11\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x14\x15\n\x0b\n\
+    \x04\x04\0\x02\x01\x12\x03\x04\x04\x1a\n\x0c\n\x05\x04\0\x02\x01\x05\x12\
+    \x03\x04\x04\x08\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\t\x15\n\x0c\n\
+    \x05\x04\0\x02\x01\x03\x12\x03\x04\x18\x19b\x06proto3\
+";
+
+static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
+
+fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto {
+    ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap()
+}
+
+pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto {
+    file_descriptor_proto_lazy.get(|| {
+        parse_descriptor_proto()
+    })
+}

+ 4 - 4
rust-lib/flowy-editor/src/protobuf/model/event.rs

@@ -72,10 +72,10 @@ impl ::protobuf::reflect::ProtobufValue for EditorEvent {
 
 static file_descriptor_proto_data: &'static [u8] = b"\
     \n\x0bevent.proto*\x1c\n\x0bEditorEvent\x12\r\n\tCreateDoc\x10\0JS\n\x06\
-    \x12\x04\0\0\x03\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x05\0\x12\
-    \x04\x01\0\x03\x01\n\n\n\x03\x05\0\x01\x12\x03\x01\x05\x10\n\x0b\n\x04\
-    \x05\0\x02\0\x12\x03\x02\x04\x12\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x02\
-    \x04\r\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x02\x10\x11b\x06proto3\
+    \x12\x04\0\0\x04\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x05\0\x12\
+    \x04\x02\0\x04\x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\x10\n\x0b\n\x04\
+    \x05\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x03\
+    \x04\r\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\x10\x11b\x06proto3\
 ";
 
 static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

+ 3 - 0
rust-lib/flowy-editor/src/protobuf/model/mod.rs

@@ -8,3 +8,6 @@ pub use errors::*;
 
 mod event; 
 pub use event::*; 
+
+mod doc_query; 
+pub use doc_query::*; 

+ 5 - 2
rust-lib/flowy-editor/src/protobuf/proto/doc_create.proto

@@ -1,11 +1,14 @@
 syntax = "proto3";
 
 message CreateDocRequest {
-    string view_id = 1;
+    string id = 1;
     string name = 2;
+    string desc = 3;
 }
 message Doc {
     string id = 1;
     string name = 2;
-    string view_id = 3;
+    string desc = 3;
+    string path = 4;
+    string content = 5;
 }

+ 6 - 0
rust-lib/flowy-editor/src/protobuf/proto/doc_query.proto

@@ -0,0 +1,6 @@
+syntax = "proto3";
+
+message QueryDocRequest {
+    string doc_id = 1;
+    bool read_content = 2;
+}

+ 1 - 0
rust-lib/flowy-editor/src/protobuf/proto/event.proto

@@ -1,4 +1,5 @@
 syntax = "proto3";
+
 enum EditorEvent {
     CreateDoc = 0;
 }

+ 40 - 0
rust-lib/flowy-editor/src/sql_tables/doc/doc_sql.rs

@@ -0,0 +1,40 @@
+use crate::{
+    errors::EditorError,
+    module::EditorDatabase,
+    sql_tables::doc::{DocTable, DocTableChangeset},
+};
+use flowy_database::{
+    prelude::*,
+    schema::{doc_table, doc_table::dsl},
+};
+use std::sync::Arc;
+
+pub struct DocTableSql {
+    pub database: Arc<dyn EditorDatabase>,
+}
+
+impl DocTableSql {
+    pub(crate) fn write_doc_table(&self, doc_table: DocTable) -> Result<(), EditorError> {
+        let conn = self.database.db_connection()?;
+        let _ = diesel::insert_into(doc_table::table)
+            .values(doc_table)
+            .execute(&*conn)?;
+        Ok(())
+    }
+
+    pub(crate) fn update_doc_table(&self, changeset: DocTableChangeset) -> Result<(), EditorError> {
+        let conn = self.database.db_connection()?;
+        diesel_update_table!(doc_table, changeset, conn);
+        Ok(())
+    }
+
+    pub(crate) fn read_doc_table(&self, doc_id: &str) -> Result<DocTable, EditorError> {
+        let doc_table = dsl::doc_table
+            .filter(doc_table::id.eq(doc_id))
+            .first::<DocTable>(&*(self.database.db_connection()?))?;
+
+        Ok(doc_table)
+    }
+
+    pub(crate) fn delete_doc(&self, view_id: &str) -> Result<(), EditorError> { unimplemented!() }
+}

+ 61 - 0
rust-lib/flowy-editor/src/sql_tables/doc/doc_table.rs

@@ -0,0 +1,61 @@
+use crate::entities::doc::{CreateDocParams, Doc, UpdateDocParams};
+use flowy_database::schema::doc_table;
+use flowy_infra::{timestamp, uuid};
+use std::convert::TryInto;
+
+#[derive(PartialEq, Clone, Debug, Queryable, Identifiable, Insertable, Associations)]
+#[table_name = "doc_table"]
+pub(crate) struct DocTable {
+    pub id: String,
+    pub name: String,
+    pub desc: String,
+    pub path: String,
+    pub modified_time: i64,
+    pub create_time: i64,
+    pub version: i64,
+}
+
+impl DocTable {
+    pub fn new(params: CreateDocParams) -> Self {
+        let time = timestamp();
+        Self {
+            id: params.id,
+            name: params.name,
+            desc: params.desc,
+            path: "".to_owned(),
+            modified_time: time,
+            create_time: time,
+            version: 0,
+        }
+    }
+}
+
+#[derive(AsChangeset, Identifiable, Default, Debug)]
+#[table_name = "doc_table"]
+pub(crate) struct DocTableChangeset {
+    pub id: String,
+    pub name: Option<String>,
+    pub desc: Option<String>,
+}
+
+impl DocTableChangeset {
+    pub(crate) fn new(params: UpdateDocParams) -> Self {
+        Self {
+            id: params.id,
+            name: params.name,
+            desc: params.desc,
+        }
+    }
+}
+
+impl std::convert::Into<Doc> for DocTable {
+    fn into(self) -> Doc {
+        Doc {
+            id: self.id,
+            name: self.name,
+            desc: self.desc,
+            path: self.path,
+            content: "".to_string(),
+        }
+    }
+}

+ 5 - 0
rust-lib/flowy-editor/src/sql_tables/doc/mod.rs

@@ -0,0 +1,5 @@
+mod doc_sql;
+mod doc_table;
+
+pub use doc_sql::*;
+pub use doc_table::*;

+ 1 - 0
rust-lib/flowy-editor/src/sql_tables/mod.rs

@@ -0,0 +1 @@
+pub mod doc;

+ 0 - 0
rust-lib/flowy-editor/tests/editor/doc_test.rs


+ 1 - 0
rust-lib/flowy-editor/tests/editor/main.rs

@@ -0,0 +1 @@
+mod doc_test;