mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: get all databases (#1983)
This commit is contained in:
parent
5a17716fd8
commit
ad5213cfad
@ -12,7 +12,7 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'dart:async';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'database_service.dart';
|
||||
import 'database_view_service.dart';
|
||||
import 'defines.dart';
|
||||
import 'layout/layout_setting_listener.dart';
|
||||
import 'row/row_cache.dart';
|
||||
@ -67,7 +67,7 @@ class DatabaseCallbacks {
|
||||
|
||||
class DatabaseController {
|
||||
final String viewId;
|
||||
final DatabaseBackendService _databaseBackendSvc;
|
||||
final DatabaseViewBackendService _databaseViewBackendSvc;
|
||||
final FieldController fieldController;
|
||||
late DatabaseViewCache _viewCache;
|
||||
final LayoutTypePB layoutType;
|
||||
@ -87,7 +87,7 @@ class DatabaseController {
|
||||
|
||||
DatabaseController({required ViewPB view, required this.layoutType})
|
||||
: viewId = view.id,
|
||||
_databaseBackendSvc = DatabaseBackendService(viewId: view.id),
|
||||
_databaseViewBackendSvc = DatabaseViewBackendService(viewId: view.id),
|
||||
fieldController = FieldController(viewId: view.id),
|
||||
groupListener = DatabaseGroupListener(view.id),
|
||||
layoutListener = DatabaseLayoutListener(view.id) {
|
||||
@ -112,7 +112,7 @@ class DatabaseController {
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> open() async {
|
||||
return _databaseBackendSvc.openGrid().then((result) {
|
||||
return _databaseViewBackendSvc.openGrid().then((result) {
|
||||
return result.fold(
|
||||
(database) async {
|
||||
_databaseCallbacks?.onDatabaseChanged?.call(database);
|
||||
@ -152,7 +152,7 @@ class DatabaseController {
|
||||
cellDataByFieldId = rowBuilder.build();
|
||||
}
|
||||
|
||||
return _databaseBackendSvc.createRow(
|
||||
return _databaseViewBackendSvc.createRow(
|
||||
startRowId: startRowId,
|
||||
groupId: groupId,
|
||||
cellDataByFieldId: cellDataByFieldId,
|
||||
@ -161,7 +161,7 @@ class DatabaseController {
|
||||
|
||||
Future<Either<Unit, FlowyError>> moveRow(RowPB fromRow,
|
||||
{RowPB? toRow, String? groupId}) {
|
||||
return _databaseBackendSvc.moveRow(
|
||||
return _databaseViewBackendSvc.moveRow(
|
||||
fromRowId: fromRow.id,
|
||||
toGroupId: groupId,
|
||||
toRowId: toRow?.id,
|
||||
@ -170,7 +170,7 @@ class DatabaseController {
|
||||
|
||||
Future<Either<Unit, FlowyError>> moveGroup(
|
||||
{required String fromGroupId, required String toGroupId}) {
|
||||
return _databaseBackendSvc.moveGroup(
|
||||
return _databaseViewBackendSvc.moveGroup(
|
||||
fromGroupId: fromGroupId,
|
||||
toGroupId: toGroupId,
|
||||
);
|
||||
@ -178,7 +178,7 @@ class DatabaseController {
|
||||
|
||||
Future<void> updateCalenderLayoutSetting(
|
||||
CalendarLayoutSettingsPB layoutSetting) async {
|
||||
await _databaseBackendSvc
|
||||
await _databaseViewBackendSvc
|
||||
.updateLayoutSetting(calendarLayoutSetting: layoutSetting)
|
||||
.then((result) {
|
||||
result.fold((l) => null, (r) => Log.error(r));
|
||||
@ -186,13 +186,13 @@ class DatabaseController {
|
||||
}
|
||||
|
||||
Future<void> dispose() async {
|
||||
await _databaseBackendSvc.closeView();
|
||||
await _databaseViewBackendSvc.closeView();
|
||||
await fieldController.dispose();
|
||||
await groupListener.stop();
|
||||
}
|
||||
|
||||
Future<void> _loadGroups() async {
|
||||
final result = await _databaseBackendSvc.loadGroups();
|
||||
final result = await _databaseViewBackendSvc.loadGroups();
|
||||
return Future(
|
||||
() => result.fold(
|
||||
(groups) {
|
||||
@ -204,7 +204,7 @@ class DatabaseController {
|
||||
}
|
||||
|
||||
Future<void> _loadLayoutSetting() async {
|
||||
_databaseBackendSvc.getLayoutSetting(layoutType).then((result) {
|
||||
_databaseViewBackendSvc.getLayoutSetting(layoutType).then((result) {
|
||||
result.fold(
|
||||
(l) {
|
||||
_layoutCallbacks?.onLoadLayout(l);
|
||||
|
@ -1,121 +1,13 @@
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/calendar_entities.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/database_entities.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/group_changeset.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/setting_entities.pb.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/database_entities.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/field_entities.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/group.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/row_entities.pb.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
|
||||
class DatabaseBackendService {
|
||||
final String viewId;
|
||||
DatabaseBackendService({
|
||||
required this.viewId,
|
||||
});
|
||||
|
||||
Future<Either<DatabasePB, FlowyError>> openGrid() async {
|
||||
await FolderEventSetLatestView(ViewIdPB(value: viewId)).send();
|
||||
|
||||
final payload = DatabaseViewIdPB(value: viewId);
|
||||
return DatabaseEventGetDatabase(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<RowPB, FlowyError>> createRow({
|
||||
String? startRowId,
|
||||
String? groupId,
|
||||
Map<String, String>? cellDataByFieldId,
|
||||
}) {
|
||||
var payload = CreateRowPayloadPB.create()..viewId = viewId;
|
||||
if (startRowId != null) {
|
||||
payload.startRowId = startRowId;
|
||||
}
|
||||
|
||||
if (groupId != null) {
|
||||
payload.groupId = groupId;
|
||||
}
|
||||
|
||||
if (cellDataByFieldId != null && cellDataByFieldId.isNotEmpty) {
|
||||
payload.data = RowDataPB(cellDataByFieldId: cellDataByFieldId);
|
||||
}
|
||||
|
||||
return DatabaseEventCreateRow(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> moveRow({
|
||||
required String fromRowId,
|
||||
required String? toGroupId,
|
||||
required String? toRowId,
|
||||
}) {
|
||||
var payload = MoveGroupRowPayloadPB.create()
|
||||
..viewId = viewId
|
||||
..fromRowId = fromRowId;
|
||||
if (toGroupId != null) {
|
||||
payload.toGroupId = toGroupId;
|
||||
}
|
||||
|
||||
if (toRowId != null) {
|
||||
payload.toRowId = toRowId;
|
||||
}
|
||||
|
||||
return DatabaseEventMoveGroupRow(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> moveGroup({
|
||||
required String fromGroupId,
|
||||
required String toGroupId,
|
||||
}) {
|
||||
final payload = MoveGroupPayloadPB.create()
|
||||
..viewId = viewId
|
||||
..fromGroupId = fromGroupId
|
||||
..toGroupId = toGroupId;
|
||||
|
||||
return DatabaseEventMoveGroup(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<List<FieldPB>, FlowyError>> getFields(
|
||||
{List<FieldIdPB>? fieldIds}) {
|
||||
var payload = GetFieldPayloadPB.create()..viewId = viewId;
|
||||
|
||||
if (fieldIds != null) {
|
||||
payload.fieldIds = RepeatedFieldIdPB(items: fieldIds);
|
||||
}
|
||||
return DatabaseEventGetFields(payload).send().then((result) {
|
||||
static Future<Either<List<DatabaseDescriptionPB>, FlowyError>>
|
||||
getAllDatabase() {
|
||||
return DatabaseEventGetDatabases().send().then((result) {
|
||||
return result.fold((l) => left(l.items), (r) => right(r));
|
||||
});
|
||||
}
|
||||
|
||||
Future<Either<LayoutSettingPB, FlowyError>> getLayoutSetting(
|
||||
LayoutTypePB layoutType) {
|
||||
final payload = DatabaseLayoutIdPB.create()
|
||||
..viewId = viewId
|
||||
..layout = layoutType;
|
||||
return DatabaseEventGetLayoutSetting(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> updateLayoutSetting(
|
||||
{CalendarLayoutSettingsPB? calendarLayoutSetting}) {
|
||||
final layoutSetting = LayoutSettingPB.create();
|
||||
if (calendarLayoutSetting != null) {
|
||||
layoutSetting.calendar = calendarLayoutSetting;
|
||||
}
|
||||
|
||||
final payload = UpdateLayoutSettingPB.create()
|
||||
..viewId = viewId
|
||||
..layoutSetting = layoutSetting;
|
||||
|
||||
return DatabaseEventSetLayoutSetting(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> closeView() {
|
||||
final request = ViewIdPB(value: viewId);
|
||||
return FolderEventCloseView(request).send();
|
||||
}
|
||||
|
||||
Future<Either<RepeatedGroupPB, FlowyError>> loadGroups() {
|
||||
final payload = DatabaseViewIdPB(value: viewId);
|
||||
return DatabaseEventGetGroups(payload).send();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,121 @@
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/calendar_entities.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/database_entities.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/group_changeset.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/setting_entities.pb.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/field_entities.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/group.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database/row_entities.pb.dart';
|
||||
|
||||
class DatabaseViewBackendService {
|
||||
final String viewId;
|
||||
DatabaseViewBackendService({
|
||||
required this.viewId,
|
||||
});
|
||||
|
||||
Future<Either<DatabasePB, FlowyError>> openGrid() async {
|
||||
await FolderEventSetLatestView(ViewIdPB(value: viewId)).send();
|
||||
|
||||
final payload = DatabaseViewIdPB(value: viewId);
|
||||
return DatabaseEventGetDatabase(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<RowPB, FlowyError>> createRow({
|
||||
String? startRowId,
|
||||
String? groupId,
|
||||
Map<String, String>? cellDataByFieldId,
|
||||
}) {
|
||||
var payload = CreateRowPayloadPB.create()..viewId = viewId;
|
||||
if (startRowId != null) {
|
||||
payload.startRowId = startRowId;
|
||||
}
|
||||
|
||||
if (groupId != null) {
|
||||
payload.groupId = groupId;
|
||||
}
|
||||
|
||||
if (cellDataByFieldId != null && cellDataByFieldId.isNotEmpty) {
|
||||
payload.data = RowDataPB(cellDataByFieldId: cellDataByFieldId);
|
||||
}
|
||||
|
||||
return DatabaseEventCreateRow(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> moveRow({
|
||||
required String fromRowId,
|
||||
required String? toGroupId,
|
||||
required String? toRowId,
|
||||
}) {
|
||||
var payload = MoveGroupRowPayloadPB.create()
|
||||
..viewId = viewId
|
||||
..fromRowId = fromRowId;
|
||||
if (toGroupId != null) {
|
||||
payload.toGroupId = toGroupId;
|
||||
}
|
||||
|
||||
if (toRowId != null) {
|
||||
payload.toRowId = toRowId;
|
||||
}
|
||||
|
||||
return DatabaseEventMoveGroupRow(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> moveGroup({
|
||||
required String fromGroupId,
|
||||
required String toGroupId,
|
||||
}) {
|
||||
final payload = MoveGroupPayloadPB.create()
|
||||
..viewId = viewId
|
||||
..fromGroupId = fromGroupId
|
||||
..toGroupId = toGroupId;
|
||||
|
||||
return DatabaseEventMoveGroup(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<List<FieldPB>, FlowyError>> getFields(
|
||||
{List<FieldIdPB>? fieldIds}) {
|
||||
var payload = GetFieldPayloadPB.create()..viewId = viewId;
|
||||
|
||||
if (fieldIds != null) {
|
||||
payload.fieldIds = RepeatedFieldIdPB(items: fieldIds);
|
||||
}
|
||||
return DatabaseEventGetFields(payload).send().then((result) {
|
||||
return result.fold((l) => left(l.items), (r) => right(r));
|
||||
});
|
||||
}
|
||||
|
||||
Future<Either<LayoutSettingPB, FlowyError>> getLayoutSetting(
|
||||
LayoutTypePB layoutType) {
|
||||
final payload = DatabaseLayoutIdPB.create()
|
||||
..viewId = viewId
|
||||
..layout = layoutType;
|
||||
return DatabaseEventGetLayoutSetting(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> updateLayoutSetting(
|
||||
{CalendarLayoutSettingsPB? calendarLayoutSetting}) {
|
||||
final layoutSetting = LayoutSettingPB.create();
|
||||
if (calendarLayoutSetting != null) {
|
||||
layoutSetting.calendar = calendarLayoutSetting;
|
||||
}
|
||||
|
||||
final payload = UpdateLayoutSettingPB.create()
|
||||
..viewId = viewId
|
||||
..layoutSetting = layoutSetting;
|
||||
|
||||
return DatabaseEventSetLayoutSetting(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> closeView() {
|
||||
final request = ViewIdPB(value: viewId);
|
||||
return FolderEventCloseView(request).send();
|
||||
}
|
||||
|
||||
Future<Either<RepeatedGroupPB, FlowyError>> loadGroups() {
|
||||
final payload = DatabaseViewIdPB(value: viewId);
|
||||
return DatabaseEventGetGroups(payload).send();
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import 'package:appflowy_backend/protobuf/flowy-database/util.pb.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../grid/presentation/widgets/filter/filter_info.dart';
|
||||
import '../../grid/presentation/widgets/sort/sort_info.dart';
|
||||
import '../database_service.dart';
|
||||
import '../database_view_service.dart';
|
||||
import '../filter/filter_listener.dart';
|
||||
import '../filter/filter_service.dart';
|
||||
import '../row/row_cache.dart';
|
||||
@ -80,7 +80,7 @@ class FieldController {
|
||||
final SortsListener _sortsListener;
|
||||
|
||||
// FFI services
|
||||
final DatabaseBackendService _databaseBackendSvc;
|
||||
final DatabaseViewBackendService _databaseViewBackendSvc;
|
||||
final SettingBackendService _settingBackendSvc;
|
||||
final FilterBackendService _filterBackendSvc;
|
||||
final SortBackendService _sortBackendSvc;
|
||||
@ -152,7 +152,7 @@ class FieldController {
|
||||
_settingListener = DatabaseSettingListener(viewId: viewId),
|
||||
_filterBackendSvc = FilterBackendService(viewId: viewId),
|
||||
_filtersListener = FiltersListener(viewId: viewId),
|
||||
_databaseBackendSvc = DatabaseBackendService(viewId: viewId),
|
||||
_databaseViewBackendSvc = DatabaseViewBackendService(viewId: viewId),
|
||||
_sortBackendSvc = SortBackendService(viewId: viewId),
|
||||
_sortsListener = SortsListener(viewId: viewId),
|
||||
_settingBackendSvc = SettingBackendService(viewId: viewId) {
|
||||
@ -448,7 +448,7 @@ class FieldController {
|
||||
Future<Either<Unit, FlowyError>> loadFields({
|
||||
required List<FieldIdPB> fieldIds,
|
||||
}) async {
|
||||
final result = await _databaseBackendSvc.getFields(fieldIds: fieldIds);
|
||||
final result = await _databaseViewBackendSvc.getFields(fieldIds: fieldIds);
|
||||
return Future(
|
||||
() => result.fold(
|
||||
(newFields) {
|
||||
|
@ -59,7 +59,7 @@ class _BuiltInPageWidgetState extends State<BuiltInPageWidget> {
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
future: AppService().getView(appID, gridID),
|
||||
future: AppBackendService().getView(appID, gridID),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
||||
);
|
||||
}
|
||||
},
|
||||
future: AppService().fetchViews(widget.layoutType),
|
||||
future: AppBackendService().fetchViews(widget.layoutType),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,11 @@ import 'package:dartz/dartz.dart';
|
||||
part 'app_bloc.freezed.dart';
|
||||
|
||||
class AppBloc extends Bloc<AppEvent, AppState> {
|
||||
final AppService appService;
|
||||
final AppBackendService appService;
|
||||
final AppListener appListener;
|
||||
|
||||
AppBloc({required AppPB app})
|
||||
: appService = AppService(),
|
||||
: appService = AppBackendService(),
|
||||
appListener = AppListener(appId: app.id),
|
||||
super(AppState.initial(app)) {
|
||||
on<AppEvent>((event, emit) async {
|
||||
|
@ -8,7 +8,7 @@ import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/app.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
|
||||
class AppService {
|
||||
class AppBackendService {
|
||||
Future<Either<AppPB, FlowyError>> readApp({required String appId}) {
|
||||
final payload = AppIdPB.create()..value = appId;
|
||||
|
||||
@ -21,9 +21,18 @@ class AppService {
|
||||
String? desc,
|
||||
required ViewLayoutTypePB layoutType,
|
||||
|
||||
/// The initial data should be the JSON of the doucment
|
||||
/// For example: {"document":{"type":"editor","children":[]}}
|
||||
/// The initial data should be the JSON of the document.
|
||||
/// Currently, only support create document with initial data.
|
||||
///
|
||||
/// The initial data must be follow this format as shown below.
|
||||
/// {"document":{"type":"editor","children":[]}}
|
||||
String? initialData,
|
||||
|
||||
/// The [ext] is used to pass through the custom configuration
|
||||
/// to the backend.
|
||||
/// Linking the view to the existing database, it needs to pass
|
||||
/// the database id. For example: "database_id": "xxx"
|
||||
///
|
||||
Map<String, String> ext = const {},
|
||||
}) {
|
||||
final payload = CreateViewPayloadPB.create()
|
||||
|
@ -13,11 +13,11 @@ class ViewSectionBloc extends Bloc<ViewSectionEvent, ViewSectionState> {
|
||||
void Function()? _viewsListener;
|
||||
void Function()? _selectedViewlistener;
|
||||
final AppViewDataContext _appViewData;
|
||||
late final AppService _appService;
|
||||
late final AppBackendService _appService;
|
||||
|
||||
ViewSectionBloc({
|
||||
required AppViewDataContext appViewData,
|
||||
}) : _appService = AppService(),
|
||||
}) : _appService = AppBackendService(),
|
||||
_appViewData = appViewData,
|
||||
super(ViewSectionState.initial(appViewData)) {
|
||||
on<ViewSectionEvent>((event, emit) async {
|
||||
|
@ -30,7 +30,7 @@ class AppFlowyBoardTest {
|
||||
Future<BoardTestContext> createTestBoard() async {
|
||||
final app = await unitTest.createTestApp();
|
||||
final builder = BoardPluginBuilder();
|
||||
return AppService()
|
||||
return AppBackendService()
|
||||
.createView(
|
||||
appId: app.id,
|
||||
name: "Test Board",
|
||||
|
@ -8,7 +8,7 @@ import '../util.dart';
|
||||
Future<GridTestContext> createTestFilterGrid(AppFlowyGridTest gridTest) async {
|
||||
final app = await gridTest.unitTest.createTestApp();
|
||||
final builder = GridPluginBuilder();
|
||||
final context = await AppService()
|
||||
final context = await AppBackendService()
|
||||
.createView(
|
||||
appId: app.id,
|
||||
name: "Filter Grid",
|
||||
|
@ -165,7 +165,7 @@ class AppFlowyGridTest {
|
||||
Future<GridTestContext> createTestGrid() async {
|
||||
final app = await unitTest.createTestApp();
|
||||
final builder = GridPluginBuilder();
|
||||
final context = await AppService()
|
||||
final context = await AppBackendService()
|
||||
.createView(
|
||||
appId: app.id,
|
||||
name: "Test Grid",
|
||||
|
@ -155,7 +155,7 @@ impl TryInto<MoveGroupRowParams> for MoveGroupRowPayloadPB {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct DatabaseDescPB {
|
||||
pub struct DatabaseDescriptionPB {
|
||||
#[pb(index = 1)]
|
||||
pub name: String,
|
||||
|
||||
@ -164,9 +164,9 @@ pub struct DatabaseDescPB {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct RepeatedDatabaseDescPB {
|
||||
pub struct RepeatedDatabaseDescriptionPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<DatabaseDescPB>,
|
||||
pub items: Vec<DatabaseDescriptionPB>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
|
@ -575,17 +575,17 @@ pub(crate) async fn move_group_row_handler(
|
||||
#[tracing::instrument(level = "debug", skip(manager), err)]
|
||||
pub(crate) async fn get_databases_handler(
|
||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||
) -> DataResult<RepeatedDatabaseDescPB, FlowyError> {
|
||||
) -> DataResult<RepeatedDatabaseDescriptionPB, FlowyError> {
|
||||
let items = manager
|
||||
.get_databases()
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|database_info| DatabaseDescPB {
|
||||
.map(|database_info| DatabaseDescriptionPB {
|
||||
name: database_info.name,
|
||||
database_id: database_info.database_id,
|
||||
})
|
||||
.collect::<Vec<DatabaseDescPB>>();
|
||||
data_result_ok(RepeatedDatabaseDescPB { items })
|
||||
.collect::<Vec<DatabaseDescriptionPB>>();
|
||||
data_result_ok(RepeatedDatabaseDescriptionPB { items })
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
|
@ -238,7 +238,8 @@ pub enum DatabaseEvent {
|
||||
#[event(input = "MoveGroupRowPayloadPB")]
|
||||
GroupByField = 113,
|
||||
|
||||
#[event(output = "RepeatedDatabaseDescPB")]
|
||||
/// Returns all the databases
|
||||
#[event(output = "RepeatedDatabaseDescriptionPB")]
|
||||
GetDatabases = 114,
|
||||
|
||||
#[event(input = "UpdateLayoutSettingPB")]
|
||||
|
@ -7,7 +7,9 @@ use crate::services::database_view::{
|
||||
make_database_view_rev_manager, make_database_view_revision_pad, DatabaseViewEditor,
|
||||
};
|
||||
use crate::services::persistence::block_index::BlockRowIndexer;
|
||||
use crate::services::persistence::database_ref::{DatabaseInfo, DatabaseRef, DatabaseRefIndexer};
|
||||
use crate::services::persistence::database_ref::{
|
||||
DatabaseInfo, DatabaseRefIndexer, DatabaseViewRef,
|
||||
};
|
||||
use crate::services::persistence::kv::DatabaseKVPersistence;
|
||||
use crate::services::persistence::migration::DatabaseMigration;
|
||||
use crate::services::persistence::rev_sqlite::{
|
||||
@ -192,7 +194,10 @@ impl DatabaseManager {
|
||||
self.database_ref_indexer.get_all_databases()
|
||||
}
|
||||
|
||||
pub async fn get_database_ref_views(&self, database_id: &str) -> FlowyResult<Vec<DatabaseRef>> {
|
||||
pub async fn get_database_ref_views(
|
||||
&self,
|
||||
database_id: &str,
|
||||
) -> FlowyResult<Vec<DatabaseViewRef>> {
|
||||
self
|
||||
.database_ref_indexer
|
||||
.get_ref_views_with_database(database_id)
|
||||
@ -425,13 +430,13 @@ pub async fn create_new_database(
|
||||
}
|
||||
|
||||
impl DatabaseRefIndexerQuery for DatabaseRefIndexer {
|
||||
fn get_ref_views(&self, database_id: &str) -> FlowyResult<Vec<DatabaseRef>> {
|
||||
fn get_ref_views(&self, database_id: &str) -> FlowyResult<Vec<DatabaseViewRef>> {
|
||||
self.get_ref_views_with_database(database_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl DatabaseRefIndexerQuery for Arc<DatabaseRefIndexer> {
|
||||
fn get_ref_views(&self, database_id: &str) -> FlowyResult<Vec<DatabaseRef>> {
|
||||
fn get_ref_views(&self, database_id: &str) -> FlowyResult<Vec<DatabaseViewRef>> {
|
||||
(**self).get_ref_views(database_id)
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ use crate::services::database_view::{
|
||||
};
|
||||
use crate::services::filter::FilterType;
|
||||
use crate::services::persistence::block_index::BlockRowIndexer;
|
||||
use crate::services::persistence::database_ref::DatabaseRef;
|
||||
use crate::services::persistence::database_ref::DatabaseViewRef;
|
||||
use crate::services::row::{DatabaseBlockRow, DatabaseBlockRowRevision, RowRevisionBuilder};
|
||||
use bytes::Bytes;
|
||||
use database_model::*;
|
||||
@ -42,7 +42,7 @@ use std::sync::Arc;
|
||||
use tokio::sync::{broadcast, RwLock};
|
||||
|
||||
pub trait DatabaseRefIndexerQuery: Send + Sync + 'static {
|
||||
fn get_ref_views(&self, database_id: &str) -> FlowyResult<Vec<DatabaseRef>>;
|
||||
fn get_ref_views(&self, database_id: &str) -> FlowyResult<Vec<DatabaseViewRef>>;
|
||||
}
|
||||
|
||||
pub struct DatabaseEditor {
|
||||
|
@ -45,7 +45,10 @@ impl DatabaseRefIndexer {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_ref_views_with_database(&self, database_id: &str) -> FlowyResult<Vec<DatabaseRef>> {
|
||||
pub fn get_ref_views_with_database(
|
||||
&self,
|
||||
database_id: &str,
|
||||
) -> FlowyResult<Vec<DatabaseViewRef>> {
|
||||
let conn = self.database.get_db_connection()?;
|
||||
let views = dsl::database_refs
|
||||
.filter(database_refs::database_id.like(database_id))
|
||||
@ -93,12 +96,12 @@ struct DatabaseRefRecord {
|
||||
database_id: String,
|
||||
}
|
||||
|
||||
pub struct DatabaseRef {
|
||||
pub struct DatabaseViewRef {
|
||||
pub view_id: String,
|
||||
pub name: String,
|
||||
pub database_id: String,
|
||||
}
|
||||
impl std::convert::From<DatabaseRefRecord> for DatabaseRef {
|
||||
impl std::convert::From<DatabaseRefRecord> for DatabaseViewRef {
|
||||
fn from(record: DatabaseRefRecord) -> Self {
|
||||
Self {
|
||||
view_id: record.view_id,
|
||||
|
@ -2,12 +2,12 @@ use crate::database::block_test::util::DatabaseRowTestBuilder;
|
||||
use crate::database::database_editor::DatabaseEditorTest;
|
||||
use database_model::RowRevision;
|
||||
use flowy_database::services::database::DatabaseEditor;
|
||||
use flowy_database::services::persistence::database_ref::{DatabaseInfo, DatabaseRef};
|
||||
use flowy_database::services::persistence::database_ref::{DatabaseInfo, DatabaseViewRef};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub enum DatabaseRefScript {
|
||||
LinkGridToDatabase {
|
||||
pub enum LinkDatabaseTestScript {
|
||||
CreateGridViewAndLinkToDatabase {
|
||||
database_id: String,
|
||||
},
|
||||
#[allow(dead_code)]
|
||||
@ -28,17 +28,17 @@ pub enum DatabaseRefScript {
|
||||
},
|
||||
}
|
||||
|
||||
pub struct DatabaseRefTest {
|
||||
pub struct LinkDatabaseTest {
|
||||
inner: DatabaseEditorTest,
|
||||
}
|
||||
|
||||
impl DatabaseRefTest {
|
||||
impl LinkDatabaseTest {
|
||||
pub async fn new() -> Self {
|
||||
let inner = DatabaseEditorTest::new_grid().await;
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
pub async fn run_scripts(&mut self, scripts: Vec<DatabaseRefScript>) {
|
||||
pub async fn run_scripts(&mut self, scripts: Vec<LinkDatabaseTestScript>) {
|
||||
for script in scripts {
|
||||
self.run_script(script).await;
|
||||
}
|
||||
@ -61,7 +61,7 @@ impl DatabaseRefTest {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn all_database_ref_views(&self, database_id: &str) -> Vec<DatabaseRef> {
|
||||
pub async fn all_database_ref_views(&self, database_id: &str) -> Vec<DatabaseViewRef> {
|
||||
self
|
||||
.inner
|
||||
.sdk
|
||||
@ -87,9 +87,9 @@ impl DatabaseRefTest {
|
||||
DatabaseRowTestBuilder::new(self.block_id(view_id).await, field_revs)
|
||||
}
|
||||
|
||||
pub async fn run_script(&mut self, script: DatabaseRefScript) {
|
||||
pub async fn run_script(&mut self, script: LinkDatabaseTestScript) {
|
||||
match script {
|
||||
DatabaseRefScript::LinkGridToDatabase { database_id } => {
|
||||
LinkDatabaseTestScript::CreateGridViewAndLinkToDatabase { database_id } => {
|
||||
let mut ext = HashMap::new();
|
||||
ext.insert("database_id".to_owned(), database_id);
|
||||
self
|
||||
@ -99,7 +99,7 @@ impl DatabaseRefTest {
|
||||
.create_test_grid_view(&self.inner.app_id, "test link grid", ext)
|
||||
.await;
|
||||
},
|
||||
DatabaseRefScript::LinkBoardToDatabase { database_id } => {
|
||||
LinkDatabaseTestScript::LinkBoardToDatabase { database_id } => {
|
||||
let mut ext = HashMap::new();
|
||||
ext.insert("database_id".to_owned(), database_id);
|
||||
self
|
||||
@ -109,7 +109,7 @@ impl DatabaseRefTest {
|
||||
.create_test_board_view(&self.inner.app_id, "test link board", ext)
|
||||
.await;
|
||||
},
|
||||
DatabaseRefScript::CreateNewGrid => {
|
||||
LinkDatabaseTestScript::CreateNewGrid => {
|
||||
self
|
||||
.inner
|
||||
.sdk
|
||||
@ -117,15 +117,15 @@ impl DatabaseRefTest {
|
||||
.create_test_grid_view(&self.inner.app_id, "Create test grid", HashMap::new())
|
||||
.await;
|
||||
},
|
||||
DatabaseRefScript::AssertNumberOfDatabase { expected } => {
|
||||
LinkDatabaseTestScript::AssertNumberOfDatabase { expected } => {
|
||||
let databases = self.all_databases().await;
|
||||
assert_eq!(databases.len(), expected);
|
||||
},
|
||||
DatabaseRefScript::CreateRow { view_id, row_rev } => {
|
||||
LinkDatabaseTestScript::CreateRow { view_id, row_rev } => {
|
||||
let editor = self.get_database_editor(&view_id).await;
|
||||
let _ = editor.insert_rows(vec![row_rev]).await.unwrap();
|
||||
},
|
||||
DatabaseRefScript::AssertNumberOfRows { view_id, expected } => {
|
||||
LinkDatabaseTestScript::AssertNumberOfRows { view_id, expected } => {
|
||||
let editor = self.get_database_editor(&view_id).await;
|
||||
let rows = editor.get_all_row_revs(&view_id).await.unwrap();
|
||||
assert_eq!(rows.len(), expected);
|
||||
|
@ -1,11 +1,12 @@
|
||||
use crate::database::database_ref_test::script::DatabaseRefScript::*;
|
||||
use crate::database::database_ref_test::script::DatabaseRefTest;
|
||||
use crate::database::database_ref_test::script::LinkDatabaseTest;
|
||||
use crate::database::database_ref_test::script::LinkDatabaseTestScript::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn database_ref_number_of_database_test() {
|
||||
let mut test = DatabaseRefTest::new().await;
|
||||
async fn number_of_database_test() {
|
||||
let mut test = LinkDatabaseTest::new().await;
|
||||
test
|
||||
.run_scripts(vec![
|
||||
// After the LinkDatabaseTest initialize, it will create a grid.
|
||||
AssertNumberOfDatabase { expected: 1 },
|
||||
CreateNewGrid,
|
||||
AssertNumberOfDatabase { expected: 2 },
|
||||
@ -14,12 +15,12 @@ async fn database_ref_number_of_database_test() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn database_ref_link_with_existing_database_test() {
|
||||
let mut test = DatabaseRefTest::new().await;
|
||||
async fn database_view_link_with_existing_database_test() {
|
||||
let mut test = LinkDatabaseTest::new().await;
|
||||
let database = test.all_databases().await.pop().unwrap();
|
||||
test
|
||||
.run_scripts(vec![
|
||||
LinkGridToDatabase {
|
||||
CreateGridViewAndLinkToDatabase {
|
||||
database_id: database.database_id,
|
||||
},
|
||||
AssertNumberOfDatabase { expected: 1 },
|
||||
@ -28,36 +29,48 @@ async fn database_ref_link_with_existing_database_test() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn database_ref_link_with_existing_database_row_test() {
|
||||
let mut test = DatabaseRefTest::new().await;
|
||||
async fn check_number_of_rows_in_linked_database_view() {
|
||||
let mut test = LinkDatabaseTest::new().await;
|
||||
let database = test.all_databases().await.pop().unwrap();
|
||||
let view = test
|
||||
.all_database_ref_views(&database.database_id)
|
||||
.await
|
||||
.remove(0);
|
||||
|
||||
test
|
||||
.run_scripts(vec![
|
||||
LinkGridToDatabase {
|
||||
CreateGridViewAndLinkToDatabase {
|
||||
database_id: database.database_id,
|
||||
},
|
||||
AssertNumberOfDatabase { expected: 1 },
|
||||
// The initial number of rows is 6
|
||||
AssertNumberOfRows {
|
||||
view_id: view.view_id.clone(),
|
||||
expected: 6,
|
||||
},
|
||||
])
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn database_ref_create_new_row_test() {
|
||||
let mut test = DatabaseRefTest::new().await;
|
||||
async fn multiple_views_share_database_rows() {
|
||||
let mut test = LinkDatabaseTest::new().await;
|
||||
|
||||
// After the LinkDatabaseTest initialize, it will create a default database
|
||||
// with Grid layout.
|
||||
let database = test.all_databases().await.pop().unwrap();
|
||||
let database_views = test.all_database_ref_views(&database.database_id).await;
|
||||
let mut database_views = test.all_database_ref_views(&database.database_id).await;
|
||||
assert_eq!(database_views.len(), 1);
|
||||
let view_id_1 = database_views.get(0).unwrap().view_id.clone();
|
||||
let view = database_views.remove(0);
|
||||
|
||||
test
|
||||
.run_scripts(vec![
|
||||
AssertNumberOfRows {
|
||||
view_id: view_id_1.clone(),
|
||||
view_id: view.view_id.clone(),
|
||||
expected: 6,
|
||||
},
|
||||
LinkGridToDatabase {
|
||||
CreateGridViewAndLinkToDatabase {
|
||||
database_id: database.database_id.clone(),
|
||||
},
|
||||
AssertNumberOfDatabase { expected: 1 },
|
||||
])
|
||||
.await;
|
||||
|
||||
@ -84,6 +97,7 @@ async fn database_ref_create_new_row_test() {
|
||||
view_id: view_id_2,
|
||||
expected: 7,
|
||||
},
|
||||
AssertNumberOfDatabase { expected: 1 },
|
||||
])
|
||||
.await;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user