nocobase/packages/core/database/src/options-parser.ts

329 lines
9.2 KiB
TypeScript
Raw Normal View History

import { FindAttributeOptions, ModelStatic, Op, Sequelize } from 'sequelize';
import { Collection } from './collection';
2022-02-15 09:36:32 +00:00
import { Database } from './database';
import FilterParser from './filter-parser';
import { Appends, Except, FindOptions } from './repository';
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
const debug = require('debug')('noco-database');
interface OptionsParserContext {
collection: Collection;
targetKey?: string;
}
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
export class OptionsParser {
options: FindOptions;
database: Database;
collection: Collection;
model: ModelStatic<any>;
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
filterParser: FilterParser;
context: OptionsParserContext;
constructor(options: FindOptions, context: OptionsParserContext) {
const { collection } = context;
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
this.collection = collection;
this.model = collection.model;
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
this.options = options;
this.database = collection.context.database;
this.filterParser = new FilterParser(options?.filter, {
collection,
app: {
ctx: options?.context,
},
});
this.context = context;
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
}
isAssociation(key: string) {
return this.model.associations[key] !== undefined;
}
isAssociationPath(path: string) {
return this.isAssociation(path.split('.')[0]);
}
toSequelizeParams() {
2021-12-12 11:57:20 +00:00
const queryParams = this.filterParser.toSequelizeParams();
if (this.options?.filterByTk) {
2021-12-12 11:57:20 +00:00
queryParams.where = {
[Op.and]: [
queryParams.where,
{
[this.context.targetKey || this.collection.filterTargetKey]: this.options.filterByTk,
2021-12-12 11:57:20 +00:00
},
],
};
}
return this.parseSort(this.parseFields(queryParams));
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
}
/**
* parser sort options
* @param filterParams
* @protected
*/
protected parseSort(filterParams) {
2022-02-15 09:36:32 +00:00
let sort = this.options?.sort || [];
if (typeof sort === 'string') {
sort = sort.split(',');
}
const orderParams = [];
for (const sortKey of sort) {
let direction = sortKey.startsWith('-') ? 'DESC' : 'ASC';
let sortField: Array<any> = sortKey.replace('-', '').split('.');
feat: provide the underscored option for the database (#1366) * feat: underscored options * feat: underscored using hook * feat: database underscored options * feat: underscored env * fix: collectionExistsInDb * fix: test * fix: nocobase install * fix: test * fix: belongsTo association * fix: test of underscored * chore: console.log * fix: list action test * fix: dump test * chore: snakeCase algo * fix: underscored field create * fix: underscored env * fix(acl): custom appends merge strategy (#1416) * Update index.md * fix(plugin-workflow): use promise to request (#1426) * Update index.md * Update collection.md * Update index.md * Update index.md * Update collection.md * Update field.md * Update repository.md * Update has-one-repository.md * Update has-many-repository.md * Update belongs-to-many-repository.md * Update index.md * chore: translate 'Add tab' in page header (#1424) * fix: test * fix: workflow test * fix: underscored with inherits * fix: underscored test * fix: process.env.DB_UNDERSCORED * fix: process.env.DB_UNDERSCORED === 'true' * fix: test * fix: pg test * fix: underscored table name * feat: tableName & fieldName conflict check * fix: test * fix: underscored index * fix: update field unique index * fix: sync default value * fix: collection manager create field * chore: field sync * fix: pg test * chore: test * fix: test * chore: default constraint name * chore: syncUniqueIndex * feat: field destory before check * feat: field type check * fix: test * fix: test * fix: improve * fix: should destroy when fields refer to the same field * fix: acl meta with underscored --------- Co-authored-by: chenos <chenlinxh@gmail.com>
2023-02-13 13:38:47 +00:00
if (this.database.inDialect('postgres', 'sqlite')) {
direction = `${direction} NULLS LAST`;
}
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
// handle sort by association
if (sortField.length > 1) {
let associationModel = this.model;
for (let i = 0; i < sortField.length - 1; i++) {
const associationKey = sortField[i];
sortField[i] = associationModel.associations[associationKey].target;
associationModel = sortField[i];
}
feat: provide the underscored option for the database (#1366) * feat: underscored options * feat: underscored using hook * feat: database underscored options * feat: underscored env * fix: collectionExistsInDb * fix: test * fix: nocobase install * fix: test * fix: belongsTo association * fix: test of underscored * chore: console.log * fix: list action test * fix: dump test * chore: snakeCase algo * fix: underscored field create * fix: underscored env * fix(acl): custom appends merge strategy (#1416) * Update index.md * fix(plugin-workflow): use promise to request (#1426) * Update index.md * Update collection.md * Update index.md * Update index.md * Update collection.md * Update field.md * Update repository.md * Update has-one-repository.md * Update has-many-repository.md * Update belongs-to-many-repository.md * Update index.md * chore: translate 'Add tab' in page header (#1424) * fix: test * fix: workflow test * fix: underscored with inherits * fix: underscored test * fix: process.env.DB_UNDERSCORED * fix: process.env.DB_UNDERSCORED === 'true' * fix: test * fix: pg test * fix: underscored table name * feat: tableName & fieldName conflict check * fix: test * fix: underscored index * fix: update field unique index * fix: sync default value * fix: collection manager create field * chore: field sync * fix: pg test * chore: test * fix: test * chore: default constraint name * chore: syncUniqueIndex * feat: field destory before check * feat: field type check * fix: test * fix: test * fix: improve * fix: should destroy when fields refer to the same field * fix: acl meta with underscored --------- Co-authored-by: chenos <chenlinxh@gmail.com>
2023-02-13 13:38:47 +00:00
} else {
const rawField = this.model.rawAttributes[sortField[0]];
sortField[0] = rawField?.field || sortField[0];
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
}
feat: provide the underscored option for the database (#1366) * feat: underscored options * feat: underscored using hook * feat: database underscored options * feat: underscored env * fix: collectionExistsInDb * fix: test * fix: nocobase install * fix: test * fix: belongsTo association * fix: test of underscored * chore: console.log * fix: list action test * fix: dump test * chore: snakeCase algo * fix: underscored field create * fix: underscored env * fix(acl): custom appends merge strategy (#1416) * Update index.md * fix(plugin-workflow): use promise to request (#1426) * Update index.md * Update collection.md * Update index.md * Update index.md * Update collection.md * Update field.md * Update repository.md * Update has-one-repository.md * Update has-many-repository.md * Update belongs-to-many-repository.md * Update index.md * chore: translate 'Add tab' in page header (#1424) * fix: test * fix: workflow test * fix: underscored with inherits * fix: underscored test * fix: process.env.DB_UNDERSCORED * fix: process.env.DB_UNDERSCORED === 'true' * fix: test * fix: pg test * fix: underscored table name * feat: tableName & fieldName conflict check * fix: test * fix: underscored index * fix: update field unique index * fix: sync default value * fix: collection manager create field * chore: field sync * fix: pg test * chore: test * fix: test * chore: default constraint name * chore: syncUniqueIndex * feat: field destory before check * feat: field type check * fix: test * fix: test * fix: improve * fix: should destroy when fields refer to the same field * fix: acl meta with underscored --------- Co-authored-by: chenos <chenlinxh@gmail.com>
2023-02-13 13:38:47 +00:00
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
sortField.push(direction);
if (this.database.inDialect('mysql')) {
orderParams.push([Sequelize.fn('ISNULL', Sequelize.col(`${this.model.name}.${sortField[0]}`))]);
}
orderParams.push(sortField);
}
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
if (orderParams.length > 0) {
return {
order: orderParams,
...filterParams,
};
}
return filterParams;
}
feat: database view collection (#1587) * test: create view collection * feat: view collection class * feat: list view * chore: skip sync view collection * test: should create view collection in difference schema * test: create view collection in collection manager * feat: create view collection by user sql * test: view resourcer * feat: view collection * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * refactor: connect to database view * refactor: sync from database * chore: rename list view sql * chore: list view fields api * chore: create collection without viewName * feat: bring out fields when selecting a view * chore: bring out fields when selecting a view * feat: view field inference class * chore: bring out fields when selecting a view * chore: sync form database view * chore: sync form database view * refactor: view collection local * feat: view get api * feat: database type infer * feat: integer map * chore: remove from in view list * chore: build error * chore: uniq collection * fix: typo * chore: replace collection list source field * fix: destroy view collection * chore: timestamp field map * refactor: interface avalableTypes * refactor: interface avalableTypes * chore: list fields test * refactor: interface avalableTypes * chore: uiSchema response in field source * fix: view query * chore: collection snippet * refactor: view collection support preview * fix: handle field source * fix: typo * fix: configure fileds title * fix: configure fileds title * fix: configure fileds title * fix: sync from databse interface * fix: sync from databse interface * feat: set fields api * fix: sync from databse fix * feat: possibleTypes * chore: fields get * fix: sync from databse * fix: list view test * fix: view test in difference schema * chore: comment * feat: when there is only one source collection, the view is a subset of a Collection * feat: view collection add field * fix: inherit query with schema * fix: test * fix: ci test * fix: test with schema * chore: set pg default search path * chore: mysql test * fix: test with schema * chore: test * chore: action test * chore: view column usage return type * feat: mysql field inference * fix: tableName * chore: node sql parser * fix: sql build * fix: database build * fix: mysql test * feat: view collection uiSchema title * fix: incorrect field source display when switching views * refactor: view collection not allow modify * fix: view collection is allow add, delete, and modify * fix: mysql test * fix: sqlite test * fix: sqlite test * fix: sqlite test * fix: sqlite test * chore: add id field as default target key * style: style improve * feat: load source field options * style: style improve * chore: disable remove column in view collection * chore: support creating view collection with different schemas with the same name * chore: support creating view collection with different schemas with the same name * fix: query view in difference schema * refactor: view collection viewname * fix: query view collection in difference schema * fix: field load * chore: field options * fix: mysql test * fix: uiSchema component error when using a view field in a block * fix: sqlite test * chore: test * fix: dump user views * fix: view collection can be updated and edited in table block * chore: sync from database display last field configuration * chore: loadCollections * chore: sync from database display last field configuration * fix: field options merge issues * style: preview table * fix: view collection is allow using in kanban blocks * refactor: code improve * fix: view collection can be updated an edited in calendar block * chore: disable infer field without interface * feat: preview only shows source or interface fields * fix: test * refactor: locale * feat: sql parser * chore: remove node-sql-parser * fix: yarn.lock * test: view repository * fix: view repository test * chore: console.log * chore: console.log * fix: mysql without schema * fix: mysql without schema * chore: preview with field schema * chore: tableActionInitializers * style: preview style improve * chore: parameter is filter when there is no filterByTk * fix: preview pagination * fix: preview pagination * style: preview table style improve * fix: sync from database loading * chore: preview performance optimization * chore: preview performance optimization * feat: limit & offset * chore: preview performance optimization * test: field with dot column * fix: datetime interface display * fix: missing boolean type * fix: sync * fix: sync from database * style: style improve * style: style improve * style: style improve * chore: preview table * chore: preview table * chore: preview table * fix: styling --------- Co-authored-by: katherinehhh <katherine_15995@163.com> Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
protected inheritFromSubQuery(include): any {
include.push([
feat: collection inheritance (#1069) * chore: test * chore: inherited-collection class * feat: collection inherit * feat: collection inherit * feat: inhertis sync runner * test: get parents fields * feat: collection inherit style promote * feat: sync * feat: sync alter table * feat: pgOnly Test * fix: child collection create api * feat: replace parent field * chore: reload parent fields * test: reload collection test * feat: details are displayed according to conditions * fix: typo * feat: inheritance map class * chore: is parent node * feat: display where child row created from * fix: find with appends * feat: add parent collection fields * fix: create table * feat: load fields for all children * refactor: sync fields from parent * test: has one field inhertis * feat: replace child association target * feat: should not replace child field when parent field update * test: should update inherit field when parent field update * feat: only the blocks directly inherited from the current data are displayed * fix: inherit from multiple collections * feat: only the blocks directly inherited from the current data are displayed * fix: test * feat: parent collection expend * fix: test * test: belongsToMany inherits * test: belongsToMany inherits * feat: block display * feat: collection inherite * feat: collection inherite * feat: multiple inherits * fix: sync runner * feat: collection inherite * feat: collecton inherits * feat: cannot be modified after inheritance and saving * feat: collection inherit for graph * feat: collection inherits * fix: drop inhertied field * fix: should throw error when type conflit * feat: output inherited fields * feat: bulk update collection fields * feat: collection fields * feat: collection fields * test: create relation with child table * fix: test * fix: test * fix: test * feat: style impove * test: should not replace field with difference type * feat: add text * fix: throw error when replace field with difference type * feat: overriding * feat: kan bankanban group fields * feat: calendar block fields * feat: kan bankanban group fields * fix: test * feat: relationship fields * feat: should delete child's field when parent field deleted * feat: foreign key filter * fix: build error & multiple inherit destory field * fix: test * chore: disable error * feat: no recursive update associations (#1091) * feat: update associations * fix(collection-manager): should update uiSchema * chore: flip if * feat: mutile inherits * feat: db dialect * feat: inherits show by database * chore: git hash into docker image * fix: js gzip * fix: dockerfile * chore: error message * feat: overriding * feat: overriding * feat: overriding * feat: local * feat: filter fields by interface * fix: database logging env * test: replace hasOne target * feat: add view * feat: local * chore: enable error * fix: update docs Co-authored-by: katherinehhh <katherine_15995@163.com> Co-authored-by: chenos <chenlinxh@gmail.com>
2022-11-16 04:53:58 +00:00
Sequelize.literal(`(select relname from pg_class where pg_class.oid = "${this.collection.name}".tableoid)`),
'__tableName',
feat: database view collection (#1587) * test: create view collection * feat: view collection class * feat: list view * chore: skip sync view collection * test: should create view collection in difference schema * test: create view collection in collection manager * feat: create view collection by user sql * test: view resourcer * feat: view collection * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * refactor: connect to database view * refactor: sync from database * chore: rename list view sql * chore: list view fields api * chore: create collection without viewName * feat: bring out fields when selecting a view * chore: bring out fields when selecting a view * feat: view field inference class * chore: bring out fields when selecting a view * chore: sync form database view * chore: sync form database view * refactor: view collection local * feat: view get api * feat: database type infer * feat: integer map * chore: remove from in view list * chore: build error * chore: uniq collection * fix: typo * chore: replace collection list source field * fix: destroy view collection * chore: timestamp field map * refactor: interface avalableTypes * refactor: interface avalableTypes * chore: list fields test * refactor: interface avalableTypes * chore: uiSchema response in field source * fix: view query * chore: collection snippet * refactor: view collection support preview * fix: handle field source * fix: typo * fix: configure fileds title * fix: configure fileds title * fix: configure fileds title * fix: sync from databse interface * fix: sync from databse interface * feat: set fields api * fix: sync from databse fix * feat: possibleTypes * chore: fields get * fix: sync from databse * fix: list view test * fix: view test in difference schema * chore: comment * feat: when there is only one source collection, the view is a subset of a Collection * feat: view collection add field * fix: inherit query with schema * fix: test * fix: ci test * fix: test with schema * chore: set pg default search path * chore: mysql test * fix: test with schema * chore: test * chore: action test * chore: view column usage return type * feat: mysql field inference * fix: tableName * chore: node sql parser * fix: sql build * fix: database build * fix: mysql test * feat: view collection uiSchema title * fix: incorrect field source display when switching views * refactor: view collection not allow modify * fix: view collection is allow add, delete, and modify * fix: mysql test * fix: sqlite test * fix: sqlite test * fix: sqlite test * fix: sqlite test * chore: add id field as default target key * style: style improve * feat: load source field options * style: style improve * chore: disable remove column in view collection * chore: support creating view collection with different schemas with the same name * chore: support creating view collection with different schemas with the same name * fix: query view in difference schema * refactor: view collection viewname * fix: query view collection in difference schema * fix: field load * chore: field options * fix: mysql test * fix: uiSchema component error when using a view field in a block * fix: sqlite test * chore: test * fix: dump user views * fix: view collection can be updated and edited in table block * chore: sync from database display last field configuration * chore: loadCollections * chore: sync from database display last field configuration * fix: field options merge issues * style: preview table * fix: view collection is allow using in kanban blocks * refactor: code improve * fix: view collection can be updated an edited in calendar block * chore: disable infer field without interface * feat: preview only shows source or interface fields * fix: test * refactor: locale * feat: sql parser * chore: remove node-sql-parser * fix: yarn.lock * test: view repository * fix: view repository test * chore: console.log * chore: console.log * fix: mysql without schema * fix: mysql without schema * chore: preview with field schema * chore: tableActionInitializers * style: preview style improve * chore: parameter is filter when there is no filterByTk * fix: preview pagination * fix: preview pagination * style: preview table style improve * fix: sync from database loading * chore: preview performance optimization * chore: preview performance optimization * feat: limit & offset * chore: preview performance optimization * test: field with dot column * fix: datetime interface display * fix: missing boolean type * fix: sync * fix: sync from database * style: style improve * style: style improve * style: style improve * chore: preview table * chore: preview table * chore: preview table * fix: styling --------- Co-authored-by: katherinehhh <katherine_15995@163.com> Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
]);
include.push([
Sequelize.literal(`
(SELECT n.nspname
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.oid = "${this.collection.name}".tableoid)
`),
'__schemaName',
]);
feat: collection inheritance (#1069) * chore: test * chore: inherited-collection class * feat: collection inherit * feat: collection inherit * feat: inhertis sync runner * test: get parents fields * feat: collection inherit style promote * feat: sync * feat: sync alter table * feat: pgOnly Test * fix: child collection create api * feat: replace parent field * chore: reload parent fields * test: reload collection test * feat: details are displayed according to conditions * fix: typo * feat: inheritance map class * chore: is parent node * feat: display where child row created from * fix: find with appends * feat: add parent collection fields * fix: create table * feat: load fields for all children * refactor: sync fields from parent * test: has one field inhertis * feat: replace child association target * feat: should not replace child field when parent field update * test: should update inherit field when parent field update * feat: only the blocks directly inherited from the current data are displayed * fix: inherit from multiple collections * feat: only the blocks directly inherited from the current data are displayed * fix: test * feat: parent collection expend * fix: test * test: belongsToMany inherits * test: belongsToMany inherits * feat: block display * feat: collection inherite * feat: collection inherite * feat: multiple inherits * fix: sync runner * feat: collection inherite * feat: collecton inherits * feat: cannot be modified after inheritance and saving * feat: collection inherit for graph * feat: collection inherits * fix: drop inhertied field * fix: should throw error when type conflit * feat: output inherited fields * feat: bulk update collection fields * feat: collection fields * feat: collection fields * test: create relation with child table * fix: test * fix: test * fix: test * feat: style impove * test: should not replace field with difference type * feat: add text * fix: throw error when replace field with difference type * feat: overriding * feat: kan bankanban group fields * feat: calendar block fields * feat: kan bankanban group fields * fix: test * feat: relationship fields * feat: should delete child's field when parent field deleted * feat: foreign key filter * fix: build error & multiple inherit destory field * fix: test * chore: disable error * feat: no recursive update associations (#1091) * feat: update associations * fix(collection-manager): should update uiSchema * chore: flip if * feat: mutile inherits * feat: db dialect * feat: inherits show by database * chore: git hash into docker image * fix: js gzip * fix: dockerfile * chore: error message * feat: overriding * feat: overriding * feat: overriding * feat: local * feat: filter fields by interface * fix: database logging env * test: replace hasOne target * feat: add view * feat: local * chore: enable error * fix: update docs Co-authored-by: katherinehhh <katherine_15995@163.com> Co-authored-by: chenos <chenlinxh@gmail.com>
2022-11-16 04:53:58 +00:00
}
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
protected parseFields(filterParams: any) {
const appends = this.options?.appends || [];
const except = [];
if (this.options?.attributes) {
return {
attributes: this.options.attributes,
};
}
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
let attributes: FindAttributeOptions = {
include: [],
exclude: [],
}; // out put all fields by default
feat: collection inheritance (#1069) * chore: test * chore: inherited-collection class * feat: collection inherit * feat: collection inherit * feat: inhertis sync runner * test: get parents fields * feat: collection inherit style promote * feat: sync * feat: sync alter table * feat: pgOnly Test * fix: child collection create api * feat: replace parent field * chore: reload parent fields * test: reload collection test * feat: details are displayed according to conditions * fix: typo * feat: inheritance map class * chore: is parent node * feat: display where child row created from * fix: find with appends * feat: add parent collection fields * fix: create table * feat: load fields for all children * refactor: sync fields from parent * test: has one field inhertis * feat: replace child association target * feat: should not replace child field when parent field update * test: should update inherit field when parent field update * feat: only the blocks directly inherited from the current data are displayed * fix: inherit from multiple collections * feat: only the blocks directly inherited from the current data are displayed * fix: test * feat: parent collection expend * fix: test * test: belongsToMany inherits * test: belongsToMany inherits * feat: block display * feat: collection inherite * feat: collection inherite * feat: multiple inherits * fix: sync runner * feat: collection inherite * feat: collecton inherits * feat: cannot be modified after inheritance and saving * feat: collection inherit for graph * feat: collection inherits * fix: drop inhertied field * fix: should throw error when type conflit * feat: output inherited fields * feat: bulk update collection fields * feat: collection fields * feat: collection fields * test: create relation with child table * fix: test * fix: test * fix: test * feat: style impove * test: should not replace field with difference type * feat: add text * fix: throw error when replace field with difference type * feat: overriding * feat: kan bankanban group fields * feat: calendar block fields * feat: kan bankanban group fields * fix: test * feat: relationship fields * feat: should delete child's field when parent field deleted * feat: foreign key filter * fix: build error & multiple inherit destory field * fix: test * chore: disable error * feat: no recursive update associations (#1091) * feat: update associations * fix(collection-manager): should update uiSchema * chore: flip if * feat: mutile inherits * feat: db dialect * feat: inherits show by database * chore: git hash into docker image * fix: js gzip * fix: dockerfile * chore: error message * feat: overriding * feat: overriding * feat: overriding * feat: local * feat: filter fields by interface * fix: database logging env * test: replace hasOne target * feat: add view * feat: local * chore: enable error * fix: update docs Co-authored-by: katherinehhh <katherine_15995@163.com> Co-authored-by: chenos <chenlinxh@gmail.com>
2022-11-16 04:53:58 +00:00
if (this.collection.isParent()) {
feat: database view collection (#1587) * test: create view collection * feat: view collection class * feat: list view * chore: skip sync view collection * test: should create view collection in difference schema * test: create view collection in collection manager * feat: create view collection by user sql * test: view resourcer * feat: view collection * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * refactor: connect to database view * refactor: sync from database * chore: rename list view sql * chore: list view fields api * chore: create collection without viewName * feat: bring out fields when selecting a view * chore: bring out fields when selecting a view * feat: view field inference class * chore: bring out fields when selecting a view * chore: sync form database view * chore: sync form database view * refactor: view collection local * feat: view get api * feat: database type infer * feat: integer map * chore: remove from in view list * chore: build error * chore: uniq collection * fix: typo * chore: replace collection list source field * fix: destroy view collection * chore: timestamp field map * refactor: interface avalableTypes * refactor: interface avalableTypes * chore: list fields test * refactor: interface avalableTypes * chore: uiSchema response in field source * fix: view query * chore: collection snippet * refactor: view collection support preview * fix: handle field source * fix: typo * fix: configure fileds title * fix: configure fileds title * fix: configure fileds title * fix: sync from databse interface * fix: sync from databse interface * feat: set fields api * fix: sync from databse fix * feat: possibleTypes * chore: fields get * fix: sync from databse * fix: list view test * fix: view test in difference schema * chore: comment * feat: when there is only one source collection, the view is a subset of a Collection * feat: view collection add field * fix: inherit query with schema * fix: test * fix: ci test * fix: test with schema * chore: set pg default search path * chore: mysql test * fix: test with schema * chore: test * chore: action test * chore: view column usage return type * feat: mysql field inference * fix: tableName * chore: node sql parser * fix: sql build * fix: database build * fix: mysql test * feat: view collection uiSchema title * fix: incorrect field source display when switching views * refactor: view collection not allow modify * fix: view collection is allow add, delete, and modify * fix: mysql test * fix: sqlite test * fix: sqlite test * fix: sqlite test * fix: sqlite test * chore: add id field as default target key * style: style improve * feat: load source field options * style: style improve * chore: disable remove column in view collection * chore: support creating view collection with different schemas with the same name * chore: support creating view collection with different schemas with the same name * fix: query view in difference schema * refactor: view collection viewname * fix: query view collection in difference schema * fix: field load * chore: field options * fix: mysql test * fix: uiSchema component error when using a view field in a block * fix: sqlite test * chore: test * fix: dump user views * fix: view collection can be updated and edited in table block * chore: sync from database display last field configuration * chore: loadCollections * chore: sync from database display last field configuration * fix: field options merge issues * style: preview table * fix: view collection is allow using in kanban blocks * refactor: code improve * fix: view collection can be updated an edited in calendar block * chore: disable infer field without interface * feat: preview only shows source or interface fields * fix: test * refactor: locale * feat: sql parser * chore: remove node-sql-parser * fix: yarn.lock * test: view repository * fix: view repository test * chore: console.log * chore: console.log * fix: mysql without schema * fix: mysql without schema * chore: preview with field schema * chore: tableActionInitializers * style: preview style improve * chore: parameter is filter when there is no filterByTk * fix: preview pagination * fix: preview pagination * style: preview table style improve * fix: sync from database loading * chore: preview performance optimization * chore: preview performance optimization * feat: limit & offset * chore: preview performance optimization * test: field with dot column * fix: datetime interface display * fix: missing boolean type * fix: sync * fix: sync from database * style: style improve * style: style improve * style: style improve * chore: preview table * chore: preview table * chore: preview table * fix: styling --------- Co-authored-by: katherinehhh <katherine_15995@163.com> Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
this.inheritFromSubQuery(attributes.include);
feat: collection inheritance (#1069) * chore: test * chore: inherited-collection class * feat: collection inherit * feat: collection inherit * feat: inhertis sync runner * test: get parents fields * feat: collection inherit style promote * feat: sync * feat: sync alter table * feat: pgOnly Test * fix: child collection create api * feat: replace parent field * chore: reload parent fields * test: reload collection test * feat: details are displayed according to conditions * fix: typo * feat: inheritance map class * chore: is parent node * feat: display where child row created from * fix: find with appends * feat: add parent collection fields * fix: create table * feat: load fields for all children * refactor: sync fields from parent * test: has one field inhertis * feat: replace child association target * feat: should not replace child field when parent field update * test: should update inherit field when parent field update * feat: only the blocks directly inherited from the current data are displayed * fix: inherit from multiple collections * feat: only the blocks directly inherited from the current data are displayed * fix: test * feat: parent collection expend * fix: test * test: belongsToMany inherits * test: belongsToMany inherits * feat: block display * feat: collection inherite * feat: collection inherite * feat: multiple inherits * fix: sync runner * feat: collection inherite * feat: collecton inherits * feat: cannot be modified after inheritance and saving * feat: collection inherit for graph * feat: collection inherits * fix: drop inhertied field * fix: should throw error when type conflit * feat: output inherited fields * feat: bulk update collection fields * feat: collection fields * feat: collection fields * test: create relation with child table * fix: test * fix: test * fix: test * feat: style impove * test: should not replace field with difference type * feat: add text * fix: throw error when replace field with difference type * feat: overriding * feat: kan bankanban group fields * feat: calendar block fields * feat: kan bankanban group fields * fix: test * feat: relationship fields * feat: should delete child's field when parent field deleted * feat: foreign key filter * fix: build error & multiple inherit destory field * fix: test * chore: disable error * feat: no recursive update associations (#1091) * feat: update associations * fix(collection-manager): should update uiSchema * chore: flip if * feat: mutile inherits * feat: db dialect * feat: inherits show by database * chore: git hash into docker image * fix: js gzip * fix: dockerfile * chore: error message * feat: overriding * feat: overriding * feat: overriding * feat: local * feat: filter fields by interface * fix: database logging env * test: replace hasOne target * feat: add view * feat: local * chore: enable error * fix: update docs Co-authored-by: katherinehhh <katherine_15995@163.com> Co-authored-by: chenos <chenlinxh@gmail.com>
2022-11-16 04:53:58 +00:00
}
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
if (this.options?.fields) {
// 将fields拆分为 attributes 和 appends
for (const field of this.options.fields) {
if (this.isAssociationPath(field)) {
// field is association field
appends.push(field);
} else {
// field is model attribute, change attributes to array type
if (!Array.isArray(attributes)) {
attributes = [];
if (this.collection.isParent()) {
feat: database view collection (#1587) * test: create view collection * feat: view collection class * feat: list view * chore: skip sync view collection * test: should create view collection in difference schema * test: create view collection in collection manager * feat: create view collection by user sql * test: view resourcer * feat: view collection * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * feat: view collection cannot be added, deleted, or modified * refactor: connect to database view * refactor: sync from database * chore: rename list view sql * chore: list view fields api * chore: create collection without viewName * feat: bring out fields when selecting a view * chore: bring out fields when selecting a view * feat: view field inference class * chore: bring out fields when selecting a view * chore: sync form database view * chore: sync form database view * refactor: view collection local * feat: view get api * feat: database type infer * feat: integer map * chore: remove from in view list * chore: build error * chore: uniq collection * fix: typo * chore: replace collection list source field * fix: destroy view collection * chore: timestamp field map * refactor: interface avalableTypes * refactor: interface avalableTypes * chore: list fields test * refactor: interface avalableTypes * chore: uiSchema response in field source * fix: view query * chore: collection snippet * refactor: view collection support preview * fix: handle field source * fix: typo * fix: configure fileds title * fix: configure fileds title * fix: configure fileds title * fix: sync from databse interface * fix: sync from databse interface * feat: set fields api * fix: sync from databse fix * feat: possibleTypes * chore: fields get * fix: sync from databse * fix: list view test * fix: view test in difference schema * chore: comment * feat: when there is only one source collection, the view is a subset of a Collection * feat: view collection add field * fix: inherit query with schema * fix: test * fix: ci test * fix: test with schema * chore: set pg default search path * chore: mysql test * fix: test with schema * chore: test * chore: action test * chore: view column usage return type * feat: mysql field inference * fix: tableName * chore: node sql parser * fix: sql build * fix: database build * fix: mysql test * feat: view collection uiSchema title * fix: incorrect field source display when switching views * refactor: view collection not allow modify * fix: view collection is allow add, delete, and modify * fix: mysql test * fix: sqlite test * fix: sqlite test * fix: sqlite test * fix: sqlite test * chore: add id field as default target key * style: style improve * feat: load source field options * style: style improve * chore: disable remove column in view collection * chore: support creating view collection with different schemas with the same name * chore: support creating view collection with different schemas with the same name * fix: query view in difference schema * refactor: view collection viewname * fix: query view collection in difference schema * fix: field load * chore: field options * fix: mysql test * fix: uiSchema component error when using a view field in a block * fix: sqlite test * chore: test * fix: dump user views * fix: view collection can be updated and edited in table block * chore: sync from database display last field configuration * chore: loadCollections * chore: sync from database display last field configuration * fix: field options merge issues * style: preview table * fix: view collection is allow using in kanban blocks * refactor: code improve * fix: view collection can be updated an edited in calendar block * chore: disable infer field without interface * feat: preview only shows source or interface fields * fix: test * refactor: locale * feat: sql parser * chore: remove node-sql-parser * fix: yarn.lock * test: view repository * fix: view repository test * chore: console.log * chore: console.log * fix: mysql without schema * fix: mysql without schema * chore: preview with field schema * chore: tableActionInitializers * style: preview style improve * chore: parameter is filter when there is no filterByTk * fix: preview pagination * fix: preview pagination * style: preview table style improve * fix: sync from database loading * chore: preview performance optimization * chore: preview performance optimization * feat: limit & offset * chore: preview performance optimization * test: field with dot column * fix: datetime interface display * fix: missing boolean type * fix: sync * fix: sync from database * style: style improve * style: style improve * style: style improve * chore: preview table * chore: preview table * chore: preview table * fix: styling --------- Co-authored-by: katherinehhh <katherine_15995@163.com> Co-authored-by: chenos <chenlinxh@gmail.com>
2023-04-01 13:56:01 +00:00
this.inheritFromSubQuery(attributes);
}
}
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
attributes.push(field);
}
}
}
if (this.options?.except) {
for (const exceptKey of this.options.except) {
if (this.isAssociationPath(exceptKey)) {
// except association field
except.push(exceptKey);
} else {
// if attributes is array form, ignore except
if (Array.isArray(attributes)) continue;
attributes.exclude.push(exceptKey);
}
}
}
return {
attributes,
...this.parseExcept(except, this.parseAppends(appends, filterParams)),
};
}
protected parseExcept(except: Except, filterParams: any) {
if (!except) return filterParams;
const setExcept = (queryParams: any, except: string) => {
// split exceptKey to path form
// posts.comments.content => ['posts', 'comments', 'content']
// then set except on include attributes
const exceptPath = except.split('.');
const association = exceptPath[0];
const lastLevel = exceptPath.length <= 2;
2021-12-06 13:23:34 +00:00
let existIncludeIndex = queryParams['include'].findIndex((include) => include['association'] == association);
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
if (existIncludeIndex == -1) {
// if include not exists, ignore this except
return;
}
if (lastLevel) {
// if it not have exclude form
2021-12-06 13:23:34 +00:00
if (Array.isArray(queryParams['include'][existIncludeIndex]['attributes'])) {
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
return;
} else {
2021-12-06 13:23:34 +00:00
if (!queryParams['include'][existIncludeIndex]['attributes']['exclude']) {
queryParams['include'][existIncludeIndex]['attributes']['exclude'] = [];
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
}
2021-12-06 13:23:34 +00:00
queryParams['include'][existIncludeIndex]['attributes']['exclude'].push(exceptPath[1]);
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
}
} else {
2021-12-06 13:23:34 +00:00
setExcept(queryParams['include'][existIncludeIndex], exceptPath.filter((_, index) => index !== 0).join('.'));
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
}
};
for (const exceptKey of except) {
setExcept(filterParams, exceptKey);
}
return filterParams;
}
protected parseAppends(appends: Appends, filterParams: any) {
if (!appends) return filterParams;
/**
* set include params
* @param model
* @param queryParams
* @param append
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
*/
const setInclude = (model: ModelStatic<any>, queryParams: any, append: string) => {
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
const appendFields = append.split('.');
const appendAssociation = appendFields[0];
2022-02-17 09:41:30 +00:00
const associations = model.associations;
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
// if append length less or equal 2
// example:
// appends: ['posts']
// appends: ['posts.title']
// All of these can be seen as last level
2022-02-17 04:56:52 +00:00
let lastLevel: boolean = false;
if (appendFields.length == 1) {
lastLevel = true;
}
if (appendFields.length == 2) {
const associationModel = associations[appendFields[0]].target;
if (associationModel.rawAttributes[appendFields[1]]) {
lastLevel = true;
}
}
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
// find association index
if (queryParams['include'] == undefined) {
queryParams['include'] = [];
}
let existIncludeIndex = queryParams['include'].findIndex(
(include) => include['association'] == appendAssociation,
);
// if association not exist, create it
if (existIncludeIndex == -1) {
// association not exists
queryParams['include'].push({
association: appendAssociation,
});
existIncludeIndex = queryParams['include'].length - 1;
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
}
// end appends
// without nests association
if (lastLevel) {
// get exist association attributes
2021-12-06 13:23:34 +00:00
let attributes = queryParams['include'][existIncludeIndex]['attributes'] || {
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
include: [], // all fields are output by default
};
// if need set attribute
if (appendFields.length == 2) {
if (!Array.isArray(attributes)) {
attributes = [];
}
2022-02-17 04:56:52 +00:00
const attributeName = appendFields[1];
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
// push field to it
2022-02-17 04:56:52 +00:00
attributes.push(attributeName);
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
} else {
// if attributes is empty array, change it to object
if (Array.isArray(attributes) && attributes.length == 0) {
attributes = {
include: [],
};
}
}
// set new attributes
queryParams['include'][existIncludeIndex] = {
...queryParams['include'][existIncludeIndex],
attributes,
};
} else {
2022-02-17 09:41:30 +00:00
setInclude(
model.associations[queryParams['include'][existIncludeIndex].association].target,
queryParams['include'][existIncludeIndex],
appendFields.filter((_, index) => index !== 0).join('.'),
);
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
}
};
// handle every appends
for (const append of appends) {
2022-02-17 09:41:30 +00:00
setInclude(this.model, filterParams, append);
feat: database next (#130) * FIX: database test with sqlite * more types * filter test * split filter parser * filter test * filter test: hasMany * define inverse association for belongsTo & hasMany * chore: console.log * repository count method * chore: Collection * repository filter & appends & fields & expect * repository: sort option * chore: test * add: test * find & findAndCount * chore: test * database-next: update guard * database-next: update guard associationKeysToBeUpdate * chore: comment * update-guard OneToOne Association * has one repository * support through table value * belongs to many repository * has many repository * has many repository find * fix: has many find and count * clean code * add count method * chore: multiple relation * chore: single relation * repository find * relation repository builder * repository count * repository count test * fix test * close db afterEach test * sort with associations * repository update * has many repository: destroy * belongs to many repository: destroy * add transaction decorator * belongs to many with transaction * has many with transaction * clean types * clean types * clean types * repository transaction * fix test * single relation repository with transaction * single relation repository with transaction * fix: test * fix: option parser fields append * fix: typo * fix: string type * fix: import * collection field methods * cleanup * collection sync * fix: import * fix: test * collection update field * collection update options * database hook * database test * database event test * update database event * add async emmit mixin * async model event * database import * fix: model hook type * fix: collection event * recall model.init on collection update * skip redefine collection test * skip collection model update * add model hook class * global model event support * chore * chore * change utils import * add field types * database import * more import test * test case * fix: through model init... * bugfix * fix * update database import * collection sync by foreachModel * fix collection model sync * update * add field types * custom operator * sqlite array field * postgresql array field * array query escape * mysql array operators * date operators * array field sqlite fix * association operator * date operator empty & notEmpty * fix: fields import * fix array field nested association * filter parse prepare * fix test * string field empty * add date operator test * field option types * fix typo * fix: operator name conflict * rename function Co-authored-by: Chareice <chareice@live.com>
2021-12-06 13:12:54 +00:00
}
debug('filter params: %o', filterParams);
return filterParams;
}
}