teableio/teable

View on GitHub
apps/nestjs-backend/src/db-provider/aggregation-query/postgres/single-value/single-value-aggregation.adapter.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { AggregationFunctionPostgres } from '../aggregation-function.postgres';

export class SingleValueAggregationAdapter extends AggregationFunctionPostgres {
  dateRangeOfDays(): string {
    return this.knex
      .raw(`extract(DAY FROM (MAX(??) - MIN(??)))::INTEGER`, [
        this.tableColumnRef,
        this.tableColumnRef,
      ])
      .toQuery();
  }

  dateRangeOfMonths(): string {
    return this.knex
      .raw(`CONCAT(MAX(??), ',', MIN(??))`, [this.tableColumnRef, this.tableColumnRef])
      .toQuery();
  }
}