Skip to content

Commit

Permalink
fix: use loader to load TableClazzList
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Apr 28, 2024
1 parent ac91cdc commit 0a2bd0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
37 changes: 15 additions & 22 deletions plugin/dal/lib/DataSource.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import assert from 'node:assert';
import path from 'node:path';
import fs from 'node:fs';
import {
AccessLevel,
LifecycleInit,
MultiInstanceProto,
MultiInstancePrototypeGetObjectsContext,
ObjectInfo,
ObjectInitType,
LifecycleInit,
} from '@eggjs/tegg';
import { ModuleConfigUtil, LoaderUtil, EggObject, EggObjectLifeCycleContext } from '@eggjs/tegg/helper';
import {
EggLoadUnitType,
EggObject,
EggObjectLifeCycleContext,
LoaderFactory,
ModuleConfigUtil,
} from '@eggjs/tegg/helper';
import {
DataSource as IDataSource,
DataSourceInjectName,
DataSourceQualifierAttribute,
PaginateData,
TableInfoUtil,
DataSource as IDataSource, TableModel, PaginateData,
TableModel,
} from '@eggjs/tegg/dal';
import { DataSource } from '@eggjs/dal-runtime';
import { TableModelManager } from './TableModelManager';
Expand All @@ -28,25 +34,12 @@ import { SqlMapManager } from './SqlMapManager';
const config = ModuleConfigUtil.loadModuleConfigSync(ctx.unitPath) as any | undefined;
const dataSources = Object.keys(config?.dataSource || {});
const result: ObjectInfo[] = [];
const daoDir = path.join(ctx.unitPath, 'dal/dao');
let dirents: string[];
try {
dirents = fs.readdirSync(daoDir);
} catch {
return [];
}
const daos = dirents.filter(t => t.endsWith(`DAO${LoaderUtil.extension}`));
// eslint-disable-next-line @typescript-eslint/no-var-requires
const daoClazzList = daos.map(t => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
return require(path.join(daoDir, t)).default;
});
const tableClazzList = daoClazzList.map(t => {
// eslint-disable-next-line no-proto
return Object.getPrototypeOf(t).clazzModel;
const loader = LoaderFactory.createLoader(ctx.unitPath, EggLoadUnitType.MODULE);
const clazzList = loader.load();
const tableClazzList = clazzList.filter(t => {
return TableInfoUtil.getIsTable(t);
});
const dataSourceLength = dataSources.length;

for (const dataSource of dataSources) {
const moduleClazzList = tableClazzList.filter(clazz => {
const tableParams = TableInfoUtil.getTableParams(clazz);
Expand Down
3 changes: 2 additions & 1 deletion plugin/dal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"node": ">=14.0.0"
},
"dependencies": {
"@eggjs/dal-runtime": "^3.39.1"
"@eggjs/dal-runtime": "^3.39.1",
"globby": "^11.1.0"
},
"devDependencies": {
"@eggjs/tegg-aop-plugin": "^3.39.1",
Expand Down

0 comments on commit 0a2bd0e

Please sign in to comment.