From b5ef8f172eb1da5034fe3e0482f1bf3ecbc4d9d9 Mon Sep 17 00:00:00 2001 From: killagu Date: Thu, 10 Oct 2024 15:24:20 +0800 Subject: [PATCH] chore: make generateSql async --- core/dal-runtime/src/DataSource.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/dal-runtime/src/DataSource.ts b/core/dal-runtime/src/DataSource.ts index 61412eb1..d6abd88d 100644 --- a/core/dal-runtime/src/DataSource.ts +++ b/core/dal-runtime/src/DataSource.ts @@ -28,7 +28,7 @@ export class DataSource implements IDataSource { * @param sqlName * @param data */ - generateSql(sqlName: string, data: object): ExecuteSql { + async generateSql(sqlName: string, data: object): Promise { const sql = this.sqlMap.generate(sqlName, data, this.mysqlDataSource.timezone!); const sqlType = this.sqlMap.getType(sqlName); const template = this.sqlMap.getTemplateString(sqlName); @@ -41,12 +41,12 @@ export class DataSource implements IDataSource { async count(sqlName: string, data?: any): Promise { 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); } async execute(sqlName: string, data?: any): Promise> { - 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); @@ -54,7 +54,7 @@ export class DataSource implements IDataSource { } async executeRaw(sqlName: string, data?: any): Promise> { - const executeSql = this.generateSql(sqlName, data); + const executeSql = await this.generateSql(sqlName, data); return await this.mysqlDataSource.query(executeSql.sql); } @@ -72,8 +72,8 @@ export class DataSource implements IDataSource { async paginate(sqlName: string, data: any, currentPage: number, perPageCount: number): Promise> { 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([