Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl dal for standalone tegg #197

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/dal-runtime/src/BaseSqlMap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';
import { ColumnType, IndexType, SqlType, SqlMap, TableModel } from '@eggjs/dal-decorator';
import { type EggLogger } from 'egg';
import { Logger } from '@eggjs/tegg';
import { TemplateUtil } from './TemplateUtil';

export interface GenerateSqlMap {
Comment on lines 1 to 6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [56-84]

Given the learning note about a GitHub issue opened to track the implementation of index left matching in the BaseSqlMapGenerator class, it's important to ensure that this feature is either implemented or tracked appropriately. If not already addressed, consider adding a comment or TODO in the code to remind of this pending enhancement.

Would you like me to open a follow-up GitHub issue to track the implementation of index left matching, or is there already an issue for this?

Expand All @@ -11,9 +11,9 @@ export interface GenerateSqlMap {

export class BaseSqlMapGenerator {
private readonly tableModel: TableModel;
private readonly logger: EggLogger;
private readonly logger: Logger;

constructor(tableModel: TableModel, logger: EggLogger) {
constructor(tableModel: TableModel, logger: Logger) {
this.tableModel = tableModel;
this.logger = logger;
}
Expand Down
6 changes: 3 additions & 3 deletions core/dal-runtime/src/SqlMapLoader.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import path from 'node:path';
import { TableModel, SqlMap } from '@eggjs/dal-decorator';
import { type EggLogger } from 'egg';
import { Logger } from '@eggjs/tegg';
import { BaseSqlMapGenerator } from './BaseSqlMap';
import { TableSqlMap } from './TableSqlMap';

export class SqlMapLoader {
private readonly logger: EggLogger;
private readonly logger: Logger;
private readonly tableModel: TableModel;
private readonly sqlMapPath: string;

constructor(tableModel: TableModel, moduleDir: string, logger: EggLogger) {
constructor(tableModel: TableModel, moduleDir: string, logger: Logger) {
this.sqlMapPath = path.join(moduleDir, 'dal/extension', `${tableModel.clazz.name}Extension.ts`);
this.logger = logger;
this.tableModel = tableModel;
Expand Down
8 changes: 8 additions & 0 deletions core/tegg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ export * as aop from '@eggjs/aop-decorator';
export * as orm from '@eggjs/tegg-orm-decorator';
export * as schedule from '@eggjs/tegg-schedule-decorator';
export { RuntimeConfig, ModuleConfigs, ModuleConfigHolder } from '@eggjs/tegg-common-util';

export interface Logger {
debug(message?: any, ...optionalParams: any[]): void;
log(message?: any, ...optionalParams: any[]): void;
info(message?: any, ...optionalParams: any[]): void;
warn(message?: any, ...optionalParams: any[]): void;
error(message?: any, ...optionalParams: any[]): void;
}
Comment on lines +12 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The findings indicate that EggLogger is still being used in various parts of the codebase, including core functionalities, plugins, and test fixtures. This suggests that not all components have been updated to use the newly introduced Logger interface. It's important for the development team to manually verify these occurrences to ensure they align with the intended architectural and compatibility goals, especially considering the potential for deliberate maintenance of EggLogger usage in certain scenarios.

Analysis chain

The Logger interface is well-defined, covering standard logging levels. Ensure that this interface is consistently implemented across the application and that existing logging calls are updated accordingly.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for files that might still be using the old `EggLogger` to ensure they've been updated.
rg --type ts "EggLogger"

Length of output: 2190

2 changes: 2 additions & 0 deletions plugin/dal/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path='./typings/index.d.ts'/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

必须加这个声明才能找到类型定义?


import { Application } from 'egg';
import { DalTableEggPrototypeHook } from './lib/DalTableEggPrototypeHook';
import { MysqlDataSourceManager } from './lib/MysqlDataSourceManager';
Expand Down
6 changes: 3 additions & 3 deletions plugin/dal/lib/DalTableEggPrototypeHook.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { LifecycleHook } from '@eggjs/tegg-lifecycle';
import { EggPrototype, EggPrototypeLifecycleContext } from '@eggjs/tegg-metadata';
import { TableInfoUtil, TableModel } from '@eggjs/dal-decorator';
import { EggLogger } from 'egg';
import { Logger } from '@eggjs/tegg';
import { SqlMapLoader } from '@eggjs/dal-runtime';
import { TableModelManager } from './TableModelManager';
import { SqlMapManager } from './SqlMapManager';

export class DalTableEggPrototypeHook implements LifecycleHook<EggPrototypeLifecycleContext, EggPrototype> {
private readonly logger: EggLogger;
private readonly logger: Logger;

constructor(logger: EggLogger) {
constructor(logger: Logger) {
this.logger = logger;
}

Expand Down
1 change: 1 addition & 0 deletions plugin/dal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@eggjs/tegg": "^3.33.1"
},
"devDependencies": {
"@eggjs/tegg-config": "^3.33.1",
"@eggjs/tegg-plugin": "^3.33.1",
"@types/mocha": "^10.0.1",
"@types/node": "^20.2.4",
Expand Down
3 changes: 2 additions & 1 deletion standalone/standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"@eggjs/tegg-lifecycle": "^3.33.1",
"@eggjs/tegg-loader": "^3.33.1",
"@eggjs/tegg-metadata": "^3.33.1",
"@eggjs/tegg-runtime": "^3.33.1"
"@eggjs/tegg-runtime": "^3.33.1",
"@eggjs/tegg-dal-plugin": "^3.33.1"
},
"publishConfig": {
"access": "public"
Expand Down
33 changes: 32 additions & 1 deletion standalone/standalone/src/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ import {
LoadUnitInstanceFactory,
ModuleLoadUnitInstance,
} from '@eggjs/tegg-runtime';
import { EggProtoImplClass, PrototypeUtil, ModuleConfigHolder, ModuleConfigs, ConfigSourceQualifierAttribute } from '@eggjs/tegg';
import {
EggProtoImplClass,
PrototypeUtil,
ModuleConfigHolder,
ModuleConfigs,
ConfigSourceQualifierAttribute,
Logger,
} from '@eggjs/tegg';
import { StandaloneUtil, MainRunner } from '@eggjs/tegg/standalone';
import { CrosscutAdviceFactory } from '@eggjs/tegg/aop';
import { EggObjectAopHook, EggPrototypeCrossCutHook, LoadUnitAopHook } from '@eggjs/tegg-aop-runtime';
Expand All @@ -23,6 +30,11 @@ import { StandaloneContext } from './StandaloneContext';
import { StandaloneContextHandler } from './StandaloneContextHandler';
import { ConfigSourceLoadUnitHook } from './ConfigSourceLoadUnitHook';
import { LoadUnitInnerClassHook } from './LoadUnitInnerClassHook';
import { DalTableEggPrototypeHook } from '@eggjs/tegg-dal-plugin/lib/DalTableEggPrototypeHook';
import { DalModuleLoadUnitHook } from '@eggjs/tegg-dal-plugin/lib/DalModuleLoadUnitHook';
import { MysqlDataSourceManager } from '@eggjs/tegg-dal-plugin/lib/MysqlDataSourceManager';
import { SqlMapManager } from '@eggjs/tegg-dal-plugin/lib/SqlMapManager';
import { TableModelManager } from '@eggjs/tegg-dal-plugin/lib/TableModelManager';

export interface ModuleDependency extends ReadModuleReferenceOptions {
baseDir: string;
Expand Down Expand Up @@ -50,6 +62,8 @@ export class Runner {
private runnerProto: EggPrototype;
private configSourceEggPrototypeHook: ConfigSourceLoadUnitHook;
private loadUnitMultiInstanceProtoHook: LoadUnitMultiInstanceProtoHook;
private dalTableEggPrototypeHook: DalTableEggPrototypeHook;
private dalModuleLoadUnitHook: DalModuleLoadUnitHook;

private readonly loadUnitInnerClassHook: LoadUnitInnerClassHook;
private readonly crosscutAdviceFactory: CrosscutAdviceFactory;
Expand Down Expand Up @@ -139,6 +153,13 @@ export class Runner {

this.loadUnitMultiInstanceProtoHook = new LoadUnitMultiInstanceProtoHook();
LoadUnitLifecycleUtil.registerLifecycle(this.loadUnitMultiInstanceProtoHook);

this.dalModuleLoadUnitHook = new DalModuleLoadUnitHook(this.moduleConfigs);
const loggerInnerObject = this.innerObjects.logger && this.innerObjects.logger[0];
const logger = loggerInnerObject?.obj || console;
this.dalTableEggPrototypeHook = new DalTableEggPrototypeHook(logger as Logger);
EggPrototypeLifecycleUtil.registerLifecycle(this.dalTableEggPrototypeHook);
LoadUnitLifecycleUtil.registerLifecycle(this.dalModuleLoadUnitHook);
}

async load() {
Expand Down Expand Up @@ -229,5 +250,15 @@ export class Runner {
if (this.loadUnitMultiInstanceProtoHook) {
LoadUnitLifecycleUtil.deleteLifecycle(this.loadUnitMultiInstanceProtoHook);
}

if (this.dalTableEggPrototypeHook) {
await EggPrototypeLifecycleUtil.deleteLifecycle(this.dalTableEggPrototypeHook);
}
if (this.dalModuleLoadUnitHook) {
await LoadUnitLifecycleUtil.deleteLifecycle(this.dalModuleLoadUnitHook);
}
MysqlDataSourceManager.instance.clear();
SqlMapManager.instance.clear();
TableModelManager.instance.clear();
}
}
Loading
Loading