mirror of
				https://github.com/Fabio286/antares.git
				synced 2025-06-05 21:59:22 +02:00 
			
		
		
		
	perf: remove comments from queries before execution
This commit is contained in:
		| @@ -1325,6 +1325,7 @@ export class MySQLClient extends AntaresCore { | |||||||
|     * @memberof MySQLClient |     * @memberof MySQLClient | ||||||
|     */ |     */ | ||||||
|    async raw (sql, args) { |    async raw (sql, args) { | ||||||
|  |       sql = sql.replace(/(\/\*(.|[\r\n])*?\*\/)|(--(.*|[\r\n]))/gm, ''); | ||||||
|       if (process.env.NODE_ENV === 'development') this._logger(sql);// TODO: replace BLOB content with a placeholder |       if (process.env.NODE_ENV === 'development') this._logger(sql);// TODO: replace BLOB content with a placeholder | ||||||
|  |  | ||||||
|       args = { |       args = { | ||||||
| @@ -1337,7 +1338,11 @@ export class MySQLClient extends AntaresCore { | |||||||
|       const nestTables = args.nest ? '.' : false; |       const nestTables = args.nest ? '.' : false; | ||||||
|       const resultsArr = []; |       const resultsArr = []; | ||||||
|       let paramsArr = []; |       let paramsArr = []; | ||||||
|       const queries = args.split ? sql.split(/((?:[^;'"]*(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*')[^;'"]*)+)|;/gm) : [sql]; |       const queries = args.split | ||||||
|  |          ? sql.split(/((?:[^;'"]*(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*')[^;'"]*)+)|;/gm) | ||||||
|  |             .filter(Boolean) | ||||||
|  |             .map(q => q.trim()) | ||||||
|  |          : [sql]; | ||||||
|       const isPool = typeof this._connection.getConnection === 'function'; |       const isPool = typeof this._connection.getConnection === 'function'; | ||||||
|       const connection = isPool ? await this._connection.getConnection() : this._connection; |       const connection = isPool ? await this._connection.getConnection() : this._connection; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1174,6 +1174,8 @@ export class PostgreSQLClient extends AntaresCore { | |||||||
|     * @memberof PostgreSQLClient |     * @memberof PostgreSQLClient | ||||||
|     */ |     */ | ||||||
|    async raw (sql, args) { |    async raw (sql, args) { | ||||||
|  |       sql = sql.replace(/(\/\*(.|[\r\n])*?\*\/)|(--(.*|[\r\n]))/gm, ''); | ||||||
|  |  | ||||||
|       args = { |       args = { | ||||||
|          nest: false, |          nest: false, | ||||||
|          details: false, |          details: false, | ||||||
| @@ -1186,7 +1188,11 @@ export class PostgreSQLClient extends AntaresCore { | |||||||
|  |  | ||||||
|       const resultsArr = []; |       const resultsArr = []; | ||||||
|       let paramsArr = []; |       let paramsArr = []; | ||||||
|       const queries = args.split ? sql.split(/(?!\B'[^']*);(?![^']*'\B)/gm) : [sql]; |       const queries = args.split | ||||||
|  |          ? sql.split(/(?!\B'[^']*);(?![^']*'\B)/gm) | ||||||
|  |             .filter(Boolean) | ||||||
|  |             .map(q => q.trim()) | ||||||
|  |          : [sql]; | ||||||
|  |  | ||||||
|       if (process.env.NODE_ENV === 'development') this._logger(sql);// TODO: replace BLOB content with a placeholder |       if (process.env.NODE_ENV === 'development') this._logger(sql);// TODO: replace BLOB content with a placeholder | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user