mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
* CB-4457. Add api for read subcollections firestore * CB-4457. Move firestore to ee module * CB-4457. Move firestore to ee module * CB-4457. Added annotations for firestore * CB-4457. Added metaData * CB-4457. Fixed build * CB-4457 add hasChildrenCollection flag * CB-4457. Add new resultsRow * CB-4457. Renamed SQLResultRowMetaData parameters * CB-4457 add rows with metadata to schema * CB-4457. Fix gql * CB-4457. Added logic to get Firestore subcollection * CB-4457. Refactor result, rename gql, added new type to return gql * CB-4457. Revert list to map * CB-4457. Get Subcollections info * CB-4457. Refactor code * Added sceleton for insert subcollection * CB-4457. Added isSupportsDataFilter flag for subcollection * CB-4457 add locales * CB-4457. Added isSupportsDataFilter flag for subcollection * CB-4457. Added update/insert logic for subcollection * CB-4457 support collection editing * CB-4457. Refactor after review, moved hierarchical model to ee. * CB-4457 add SerializableKey * CB-4457 keep only new rowsWithMetaData api * CB-4457 review fixes * CB-4457 review fixes * CB-4457. Refactor after review. Added logic for delete * CB-4457 pass metadata in deleted rows * CB-4457 check row for undefined * CB-4457 pass metadata when editing json * CB-4457. Refactor edit, fix icons * CB-4457. Refactor makeDocumentInputValue, created new method for locator * CB-4457 try to get the current metadata for row * CB-4457 clear cache on result update * CB-4457 remove extra check * CB-4457. Fixed npe --------- Co-authored-by: DenisSinelnikov <denis.sinelnikov@dbaever.com> Co-authored-by: naumov <iamemptyhuh@gmail.com> Co-authored-by: Aleksei Potsetsuev <wrouds@gmail.com> Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
151 lines
3.7 KiB
TypeScript
151 lines
3.7 KiB
TypeScript
/*
|
|
* CloudBeaver - Cloud Database Manager
|
|
* Copyright (C) 2020-2024 DBeaver Corp and others
|
|
*
|
|
* Licensed under the Apache License, Version 2.0.
|
|
* you may not use this file except in compliance with the License.
|
|
*/
|
|
import { makeObservable, observable } from 'mobx';
|
|
|
|
import { ResultDataFormat } from '@cloudbeaver/core-sdk';
|
|
|
|
import { DatabaseDataAction } from '../../DatabaseDataAction';
|
|
import type { IDatabaseDataSource } from '../../IDatabaseDataSource';
|
|
import type { IDatabaseResultSet } from '../../IDatabaseResultSet';
|
|
import { databaseDataAction } from '../DatabaseDataActionDecorator';
|
|
import type { IDatabaseDataCacheAction } from '../IDatabaseDataCacheAction';
|
|
import type { IResultSetElementKey, IResultSetRowKey } from './IResultSetDataKey';
|
|
import { ResultSetDataAction } from './ResultSetDataAction';
|
|
|
|
@databaseDataAction()
|
|
export class ResultSetCacheAction
|
|
extends DatabaseDataAction<any, IDatabaseResultSet>
|
|
implements IDatabaseDataCacheAction<IResultSetElementKey, IDatabaseResultSet>
|
|
{
|
|
static dataFormat = [ResultDataFormat.Resultset];
|
|
|
|
private readonly cache: Map<string, Map<symbol, any>>;
|
|
|
|
constructor(source: IDatabaseDataSource<any, IDatabaseResultSet>, private readonly data: ResultSetDataAction) {
|
|
super(source);
|
|
|
|
this.cache = new Map();
|
|
|
|
makeObservable<this, 'cache'>(this, {
|
|
cache: observable,
|
|
});
|
|
}
|
|
|
|
get<T>(key: IResultSetElementKey, scope: symbol): T | undefined {
|
|
const keyCache = this.getKeyCache(key);
|
|
if (!keyCache) {
|
|
return;
|
|
}
|
|
|
|
return keyCache.get(scope);
|
|
}
|
|
|
|
getRow<T>(key: IResultSetRowKey, scope: symbol): T | undefined {
|
|
const keyCache = this.getRowCache(key);
|
|
if (!keyCache) {
|
|
return;
|
|
}
|
|
|
|
return keyCache.get(scope);
|
|
}
|
|
|
|
has(key: IResultSetElementKey, scope: symbol) {
|
|
const keyCache = this.getKeyCache(key);
|
|
|
|
if (!keyCache) {
|
|
return false;
|
|
}
|
|
|
|
return keyCache.has(scope);
|
|
}
|
|
|
|
hasRow(key: IResultSetRowKey, scope: symbol) {
|
|
const keyCache = this.getRowCache(key);
|
|
|
|
if (!keyCache) {
|
|
return false;
|
|
}
|
|
|
|
return keyCache.has(scope);
|
|
}
|
|
|
|
set<T>(key: IResultSetElementKey, scope: symbol, value: T) {
|
|
const keyCache = this.getOrCreateKeyCache(key);
|
|
|
|
keyCache.set(scope, value);
|
|
}
|
|
|
|
setRow<T>(key: IResultSetRowKey, scope: symbol, value: T) {
|
|
const keyCache = this.getOrCreateRowKeyCache(key);
|
|
|
|
keyCache.set(scope, value);
|
|
}
|
|
|
|
delete(key: IResultSetElementKey, scope: symbol) {
|
|
const keyCache = this.getKeyCache(key);
|
|
|
|
if (keyCache) {
|
|
keyCache.delete(scope);
|
|
}
|
|
}
|
|
|
|
deleteRow(key: IResultSetRowKey, scope: symbol) {
|
|
const keyCache = this.getRowCache(key);
|
|
|
|
if (keyCache) {
|
|
keyCache.delete(scope);
|
|
}
|
|
}
|
|
|
|
afterResultUpdate() {
|
|
this.cache.clear();
|
|
}
|
|
|
|
dispose(): void {
|
|
this.cache.clear();
|
|
}
|
|
|
|
private serializeRowKey(key: IResultSetRowKey) {
|
|
return 'row:' + this.data.serializeRowKey(key);
|
|
}
|
|
|
|
private serializeKey(key: IResultSetElementKey) {
|
|
return this.data.serialize(key);
|
|
}
|
|
|
|
private getKeyCache(key: IResultSetElementKey) {
|
|
return this.cache.get(this.serializeKey(key));
|
|
}
|
|
|
|
private getRowCache(key: IResultSetRowKey) {
|
|
return this.cache.get(this.serializeRowKey(key));
|
|
}
|
|
|
|
private getOrCreateKeyCache(key: IResultSetElementKey) {
|
|
let keyCache = this.getKeyCache(key);
|
|
|
|
if (!keyCache) {
|
|
keyCache = observable(new Map());
|
|
this.cache.set(this.serializeKey(key), keyCache);
|
|
}
|
|
|
|
return keyCache;
|
|
}
|
|
|
|
private getOrCreateRowKeyCache(key: IResultSetRowKey) {
|
|
let keyCache = this.getRowCache(key);
|
|
|
|
if (!keyCache) {
|
|
keyCache = observable(new Map());
|
|
this.cache.set(this.serializeRowKey(key), keyCache);
|
|
}
|
|
|
|
return keyCache;
|
|
}
|
|
}
|