1. 修复FloatColumn对numeric的问题
2. 数据库抛出错误时,增加sql属性 3. 查询器排序问题的修复
This commit is contained in:
@ -4,6 +4,10 @@ import { DeleteBuilder, IDeleteBuilder, IInsertBuilder, InsertBuilder, ISelectBu
|
||||
import { Class } from "./types";
|
||||
import { formatSQL } from "./util";
|
||||
|
||||
interface IQueryResult<R extends QueryResultRow = any> extends QueryResult<R> {
|
||||
sql: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库基本操作
|
||||
*/
|
||||
@ -13,7 +17,7 @@ export interface IDatabase {
|
||||
* @param sql sql语句
|
||||
* @param args sql参数
|
||||
*/
|
||||
query<R extends QueryResultRow = any>(sql: string, args?: any[] | Record<string, any>): Promise<QueryResult<R>>
|
||||
query<R extends QueryResultRow = any>(sql: string, args?: any[] | Record<string, any>): Promise<IQueryResult<R>>
|
||||
|
||||
/**
|
||||
* 查询实体
|
||||
@ -83,7 +87,16 @@ class PostgresClient implements IPostgresClient {
|
||||
this.#client = client;
|
||||
}
|
||||
|
||||
public query<R extends QueryResultRow = any>(sql: string, args?: any[] | Record<string, any>): Promise<QueryResult<R>> { return this.#client.query(args ? formatSQL(sql, args) : sql); }
|
||||
public async query<R extends QueryResultRow = any>(sql: string, args?: any[] | Record<string, any>): Promise<IQueryResult<R>> {
|
||||
sql = args ? formatSQL(sql, args) : sql;
|
||||
try {
|
||||
const res = await this.#client.query(sql);
|
||||
return { ...res, sql };
|
||||
} catch (err: any) {
|
||||
err.sql = sql;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async trans() {
|
||||
@ -155,7 +168,16 @@ export const database: IPostgresDatabase = {
|
||||
if (pool) pool.end().catch((err) => console.error(err));
|
||||
},
|
||||
|
||||
query(sql, args) { return getPool().query(args ? formatSQL(sql, args) : sql); },
|
||||
async query(sql, args) {
|
||||
sql = args ? formatSQL(sql, args) : sql;
|
||||
try {
|
||||
const res = await getPool().query(sql);
|
||||
return { ...res, sql };
|
||||
} catch (err: any) {
|
||||
err.sql = sql;
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
select(Entity, alias) { return new SelectBuilder(this.query.bind(this), Entity, alias); },
|
||||
insert(Entity) { return new InsertBuilder(this.query.bind(this), Entity); },
|
||||
update(Entity) { return new UpdateBuilder(this.query.bind(this), Entity); },
|
||||
|
Reference in New Issue
Block a user