|
|
|
@ -252,7 +252,7 @@ class BaseModelSql extends BaseModel {
|
|
|
|
|
|
|
|
|
|
const query = driver(this.tn).insert(insertObj); |
|
|
|
|
|
|
|
|
|
if (this.dbDriver.clientType() === 'pg' || this.dbDriver.clientType() === 'mssql') { |
|
|
|
|
if (this.isPg() || this.dbDriver.clientType() === 'mssql') { |
|
|
|
|
query.returning(Object.entries(this.aliasToColumn).map(([val, key]) => `${key} as ${val}`)); |
|
|
|
|
response = await this._run(query); |
|
|
|
|
} |
|
|
|
@ -282,6 +282,10 @@ class BaseModelSql extends BaseModel {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private isPg() { |
|
|
|
|
return this.dbDriver.clientType() === 'pg'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update table row data by primary key |
|
|
|
|
* |
|
|
|
@ -800,6 +804,16 @@ class BaseModelSql extends BaseModel {
|
|
|
|
|
*/ |
|
|
|
|
async countByPk({where = '', conditionGraph = null}) { |
|
|
|
|
try { |
|
|
|
|
if (this.isPg() && !conditionGraph && !where) { |
|
|
|
|
return (await this._run( |
|
|
|
|
this.dbDriver.raw(`SELECT c.reltuples::bigint AS count
|
|
|
|
|
FROM pg_class c |
|
|
|
|
JOIN pg_namespace n ON n.oid = c.relnamespace |
|
|
|
|
WHERE c.relname = ? |
|
|
|
|
AND n.nspname = ?`, [this.tn,this.config?.searchPath?.[0] || 'public'])
|
|
|
|
|
))?.rows?.[0]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return await this._run(this.$db |
|
|
|
|
.conditionGraph(conditionGraph) |
|
|
|
|
.count(`${this.tn}.${(this.pks[0] || this.columns[0]).cn} as count`) |
|
|
|
|