(operations: IQueryOperations[])
| 428 | } |
| 429 | |
| 430 | async queryCount(operations: IQueryOperations[]): Promise<number> { |
| 431 | const stopTimer = this.metricTimer('queryCount'); |
| 432 | try { |
| 433 | let query: Knex.QueryBuilder = this.db.count().from(TABLE); |
| 434 | |
| 435 | operations.forEach((operation) => { |
| 436 | if (operation.op === 'where') { |
| 437 | query = this.where(query, operation.parameters); |
| 438 | } |
| 439 | |
| 440 | if (operation.op === 'forFeatures') { |
| 441 | query = this.forFeatures(query, operation.parameters); |
| 442 | } |
| 443 | |
| 444 | if (operation.op === 'beforeDate') { |
| 445 | query = this.beforeDate(query, operation.parameters); |
| 446 | } |
| 447 | |
| 448 | if (operation.op === 'betweenDate') { |
| 449 | query = this.betweenDate(query, operation.parameters); |
| 450 | } |
| 451 | }); |
| 452 | |
| 453 | const queryResult = await query.first(); |
| 454 | return Number.parseInt(queryResult.count || 0, 10); |
| 455 | } catch (_e) { |
| 456 | return 0; |
| 457 | } finally { |
| 458 | stopTimer(); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | where( |
| 463 | query: Knex.QueryBuilder, |
nothing calls this directly
no test coverage detected