anote-server-libs 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -194,9 +194,9 @@ class ModelDao extends Dao {
|
|
|
194
194
|
}));
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
-
getRowsViewCountBy(
|
|
197
|
+
getRowsViewCountBy(cols, order, offset, limit, where, inputs = [], client, lock = true) {
|
|
198
198
|
if (this.pool) {
|
|
199
|
-
return (client || this.pool).query('SELECT ' +
|
|
199
|
+
return (client || this.pool).query('SELECT ' + cols.map(r => r.indexOf(' ') > -1 ? r : ('"' + r + '"')).join(',') + ', COUNT(*) OVER() AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : '') + (order ? (' ORDER BY ' + order) : '')
|
|
200
200
|
+ (offset ? (' OFFSET ' + offset) : '') + (limit !== undefined ? (' LIMIT ' + limit) : '') + ((client && lock) ? ' FOR UPDATE' : ''), inputs)
|
|
201
201
|
.then(q => ({
|
|
202
202
|
views: q.rows.map(r => this.buildObject(r)),
|
|
@@ -208,7 +208,7 @@ class ModelDao extends Dao {
|
|
|
208
208
|
if (where)
|
|
209
209
|
where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
|
|
210
210
|
return Promise.allConcurrent(1)([
|
|
211
|
-
() => request.query('SELECT ' +
|
|
211
|
+
() => request.query('SELECT ' + cols.map(r => r.indexOf(' ') > -1 ? r : ('"' + r + '"')).join(',') + ' FROM ' + this.table
|
|
212
212
|
+ ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '') + (order ? (' ORDER BY ' + order) : '')
|
|
213
213
|
+ (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : '')),
|
|
214
214
|
() => request.query('SELECT COUNT(DISTINCT id) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : ''))
|
|
@@ -215,9 +215,9 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
getRowsViewCountBy(
|
|
218
|
+
getRowsViewCountBy(cols: string[], order?: string, offset?: number, limit?: number, where?: string, inputs: any[] = [], client?: ClientBase | Transaction, lock = true): Promise<ViewCount<any>> {
|
|
219
219
|
if(this.pool) {
|
|
220
|
-
return (<ClientBase | Pool>(client || this.pool)).query('SELECT ' +
|
|
220
|
+
return (<ClientBase | Pool>(client || this.pool)).query('SELECT ' + cols.map(r => r.indexOf(' ') > -1 ? r : ('"' + r + '"')).join(',') + ', COUNT(*) OVER() AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : '') + (order ? (' ORDER BY ' + order) : '')
|
|
221
221
|
+ (offset ? (' OFFSET ' + offset) : '') + (limit !== undefined ? (' LIMIT ' + limit) : '') + ((client && lock) ? ' FOR UPDATE' : ''), inputs)
|
|
222
222
|
.then(q => ({
|
|
223
223
|
views: q.rows.map(r => this.buildObject(r)),
|
|
@@ -227,7 +227,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
|
|
|
227
227
|
const request = (<Transaction | ConnectionPool>(client || this.poolMssql)).request();
|
|
228
228
|
if(where) where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
|
|
229
229
|
return Promise.allConcurrent(1)([
|
|
230
|
-
() => request.query('SELECT ' +
|
|
230
|
+
() => request.query('SELECT ' + cols.map(r => r.indexOf(' ') > -1 ? r : ('"' + r + '"')).join(',') + ' FROM ' + this.table
|
|
231
231
|
+ ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '') + (order ? (' ORDER BY ' + order) : '')
|
|
232
232
|
+ (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : '')),
|
|
233
233
|
() => request.query('SELECT COUNT(DISTINCT id) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : ''))
|