nocobase/packages/core/data-source-manager/src/sequelize-collection-manager.ts
ChengLei Shao 2063227f4a
refactor: export & import plugin (#4468)
* feat: chunk method in repository

* chore: xlsx export test

* chore: xlsx export

* chore: export action

* chore: export action

* chore: code

* feat: database interface manager

* feat: export with ui schema

* chore: console.log

* chore: export with china region field

* chore: export with attachments

* chore: export with multiple select

* chore: export with interface

* chore: export action

* fix: export with datetime file

* chore: limit export action running in same time

* chore: yarn.lock

* fix: render json value

* chore: chunk with limit

* feat: add EXPORT_LIMIT env config

* fix: typo

* fix: type

* chore: asyn mutex version

* chore: test

* chore: test

* fix: export null value

* chore: test

* chore: createdAt test

* fix: export with createdAt

* chore: import template

* chore: xlsx importer

* chore: import run

* chore: export with data source api

* chore: toValue api in interface

* fix: build

* chore: import with transaction

* fix: build database

* chore: many to one interface

* chore: code

* chore: import with associations

* chore: default toValue

* chore: import template with explain

* chore: import with explain template

* chore: reset id seq after import

* chore: download template action

* fix: database build

* fix: build

* fix: build

* fix: test

* chore: import with number field

* chore: import with boolean field

* chore: json interface

* chore: import action

* chore: typo

* chore: i18n

* chore: select interface

* chore: china region interface

* chore: datetiem field

* chore: cast to array

* fix: import tips

* chore: import await

* fix: test

* fix: test in mariadb

* chore: comments

* chore: comments

* fix: parse date with empty string

* fix: read import limit

* fix: type

* fix: test in mariadb

* chore: skip bigint test in sqlite

* chore: skip bigint test in sqlite

* chore: download tip i18n keys

* fix: download tips

* feat(client): add new variable named 'URL search params' and support link action (#4506)

* feat: support link action

* feat(client): add new variable named 'URL search params'

* chore: add translation

* fix: avoid crashing

* chore: fix failed test

* feat: link action

* feat: link action

* fix: remove filter parameters with undefined values

* feat: link action

* feat: add support for default values in filter form fields

* refactor: code improve

* refactor: locale improve

* refactor: locale improve

* test: add e2e test

* refactor: locale improve

* refactor: locale improve

* fix: resolve operation issues with variables

* refactor: code improve

* chore: enable direct selection of variables as default value

* chore: use qs to parse query string

* fix: menu selectKeys (T-4373)

* refactor: use qs to stringify search params

* refactor: locale improve

* refactor: locale improve

* chore: fix failed tests

* fix: resolve issue where setting Data scope is not work

* chore: fix failed e2e tests

* chore: make e2e tests more stable

* chore: add translation

* chore: make e2e tests more stable

* fix: resolve the issue of error when saving data scope

* feat: trigger variable parsing after context change

* test: add unit tests

* test: add e2e test

* refactor: extract template

* chore: fix failed unit tests

* chore: fix failed e2e test

* fix(Link): hide linkage rules in top link (T-4410)

* fix(permission): remove URL search params variable from data scope

* chore: make more stable

* chore: make e2e test more stable

* fix(Link): reduce size for variable

* fix: clear previous context (T-4449)

* fix(calendar, map): resolve initial data scope setting error (T-4450)

* fix: correct concatenation of query string (T-4453)

---------

Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: jack zhang <1098626505@qq.com>

* refactor(FormV2): add FormWithDataTemplates component (#4551)

* Revert "fix(client): fix data template style (#4536)"

This reverts commit db66090ab279508473e74803dbb8637341fa6f3f.

* refactor(FormV2): add FormWithDataTemplates component

* chore: fix failed e2e tests

* chore: make e2e test more stable

* chore: import warning i18n

* chore: import warning i18n

* fix: bug

* fix: export action loading

* fix: bug

* chore: map field interface

* fix: merge bug

---------

Co-authored-by: xilesun <2013xile@gmail.com>
Co-authored-by: Zeke Zhang <958414905@qq.com>
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: jack zhang <1098626505@qq.com>
2024-06-05 17:52:43 +08:00

116 lines
2.9 KiB
TypeScript

/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
/* istanbul ignore file -- @preserve */
import { Database } from '@nocobase/database';
import {
CollectionOptions,
ICollection,
ICollectionManager,
IFieldInterface,
IRepository,
MergeOptions,
} from './types';
export class SequelizeCollectionManager implements ICollectionManager {
db: Database;
options: any;
constructor(options) {
this.db = this.createDB(options);
this.options = options;
}
collectionsFilter() {
if (this.options.collectionsFilter) {
return this.options.collectionsFilter;
}
return (collection) => {
return collection.options.introspected;
};
}
createDB(options: any = {}) {
if (options.database instanceof Database) {
return options.database;
}
return new Database(options);
}
registerFieldTypes(types: Record<string, any>) {
this.db.registerFieldTypes(types);
}
registerFieldInterfaces() {}
registerCollectionTemplates() {}
registerModels(models: Record<string, any>) {
return this.db.registerModels(models);
}
registerRepositories(repositories: Record<string, any>) {
return this.db.registerModels(repositories);
}
getRegisteredRepository(key: any) {
if (typeof key !== 'string') {
return key;
}
return this.db.repositories.get(key);
}
defineCollection(options: CollectionOptions) {
const collection = this.db.collection(options);
// @ts-ignore
collection.model.refreshAttributes();
// @ts-ignore
collection.model._findAutoIncrementAttribute();
return collection;
}
extendCollection(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions): ICollection {
return this.db.extendCollection(collectionOptions, mergeOptions) as unknown as ICollection;
}
hasCollection(name: string) {
return this.db.hasCollection(name);
}
getCollection(name: string) {
return this.db.getCollection(name);
}
getCollections() {
const collectionsFilter = this.collectionsFilter();
return [...this.db.collections.values()].filter((collection) => collectionsFilter(collection));
}
getRepository<R = IRepository>(name: string, sourceId?: string | number): R {
return this.db.getRepository(name, sourceId) as R;
}
async sync() {
await this.db.sync();
}
registerFieldInterface(name: string, fieldInterface: new (options: any) => IFieldInterface): void {
this.db.interfaceManager.registerInterfaceType(name, fieldInterface);
}
getFieldInterface(name: string): { new (options: any): IFieldInterface | undefined } {
return this.db.interfaceManager.getInterfaceType(name);
}
}