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

chore: make generateSql async #248

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
12 changes: 6 additions & 6 deletions core/dal-runtime/src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

/**
* public for aop execute to implement sql hint append
* @param sqlName

Check warning on line 28 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (16)

Missing JSDoc @param "sqlName" description

Check warning on line 28 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (16)

Missing JSDoc @param "sqlName" description

Check warning on line 28 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (18)

Missing JSDoc @param "sqlName" description

Check warning on line 28 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (18)

Missing JSDoc @param "sqlName" description

Check warning on line 28 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (20)

Missing JSDoc @param "sqlName" description

Check warning on line 28 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (20)

Missing JSDoc @param "sqlName" description

Check warning on line 28 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (22)

Missing JSDoc @param "sqlName" description
* @param data

Check warning on line 29 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (16)

Missing JSDoc @param "data" description

Check warning on line 29 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (16)

Missing JSDoc @param "data" description

Check warning on line 29 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (18)

Missing JSDoc @param "data" description

Check warning on line 29 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (18)

Missing JSDoc @param "data" description

Check warning on line 29 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (20)

Missing JSDoc @param "data" description

Check warning on line 29 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (20)

Missing JSDoc @param "data" description

Check warning on line 29 in core/dal-runtime/src/DataSource.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (22)

Missing JSDoc @param "data" description
*/
generateSql(sqlName: string, data: object): ExecuteSql {
async generateSql(sqlName: string, data: object): Promise<ExecuteSql> {
const sql = this.sqlMap.generate(sqlName, data, this.mysqlDataSource.timezone!);
const sqlType = this.sqlMap.getType(sqlName);
const template = this.sqlMap.getTemplateString(sqlName);
Expand All @@ -41,20 +41,20 @@

async count(sqlName: string, data?: any): Promise<number> {
const newData = Object.assign({ $$count: true }, data);
const executeSql = this.generateSql(sqlName, newData);
const executeSql = await this.generateSql(sqlName, newData);
return await this.#paginateCount(executeSql.sql);
killagu marked this conversation as resolved.
Show resolved Hide resolved
}

async execute(sqlName: string, data?: any): Promise<Array<T>> {
const executeSql = this.generateSql(sqlName, data);
const executeSql = await this.generateSql(sqlName, data);
const rows = await this.mysqlDataSource.query(executeSql.sql);
return rows.map(t => {
return TableModelInstanceBuilder.buildInstance(this.tableModel, t);
});
}

async executeRaw(sqlName: string, data?: any): Promise<Array<any>> {
const executeSql = this.generateSql(sqlName, data);
const executeSql = await this.generateSql(sqlName, data);
return await this.mysqlDataSource.query(executeSql.sql);
killagu marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -72,8 +72,8 @@

async paginate(sqlName: string, data: any, currentPage: number, perPageCount: number): Promise<PaginateData<T>> {
const limit = `LIMIT ${(currentPage - 1) * perPageCount}, ${perPageCount}`;
const sql = this.generateSql(sqlName, data).sql + ' ' + limit;
const countSql = this.generateSql(sqlName, Object.assign({ $$count: true }, data)).sql;
const sql = (await this.generateSql(sqlName, data)).sql + ' ' + limit;
const countSql = (await this.generateSql(sqlName, Object.assign({ $$count: true }, data))).sql;


const ret = await Promise.all([
Expand Down
Loading