Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion core/dal-runtime/src/MySqlDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const DEFAULT_OPTIONS: RDSClientOptions = {
trace: true,
};

const DEFAULT_RETRY_TIMES = 3;

export interface EggQueryOptions extends QueryOptions {
executeType?: 'execute' | 'query';
}
Expand All @@ -40,7 +42,7 @@ export class MysqlDataSource extends Base {
this.#logger = logger;
this.forkDb = forkDb;
this.initSql = initSql ?? 'SELECT 1 + 1';
this.#initRetryTimes = initRetryTimes;
this.#initRetryTimes = initRetryTimes ?? DEFAULT_RETRY_TIMES;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

With this change, this.#initRetryTimes is guaranteed to be a number. To improve type safety and reflect this guarantee in the type system, please update its declaration on line 35 to be non-optional.

Change from:

readonly #initRetryTimes?: number;

To:

readonly #initRetryTimes: number;

this.name = name;
this.timezone = options.timezone;
this.executeType = executeType ?? 'query';
Expand Down
2 changes: 1 addition & 1 deletion core/dal-runtime/test/DataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('test/Datasource.test.ts', () => {
mm.errorOnce(RDSClient.prototype, 'query', new Error('fake error'));
const query: any = RDSClient.prototype.query;

const mysql = new MysqlDataSource(mysqlOptions);
const mysql = new MysqlDataSource({ ...mysqlOptions, initRetryTimes: 0 });
await assert.rejects(mysql.ready(), /fake error/);
assert.strictEqual(query.called, 1);
assert.deepStrictEqual(query.lastCalledArguments, [ mysqlOptions.initSql ]);
Expand Down
Loading