1
import type { Knex } from 'knex';
2
import type { FnHelperOptions } from '../types.js';
3
import { FnHelper } from '../types.js';
5
export class FnHelperMySQL extends FnHelper {
6
year(table: string, column: string): Knex.Raw {
7
return this.knex.raw('YEAR(??.??)', [table, column]);
10
month(table: string, column: string): Knex.Raw {
11
return this.knex.raw('MONTH(??.??)', [table, column]);
14
week(table: string, column: string): Knex.Raw {
15
return this.knex.raw('WEEK(??.??)', [table, column]);
18
day(table: string, column: string): Knex.Raw {
19
return this.knex.raw('DAYOFMONTH(??.??)', [table, column]);
22
weekday(table: string, column: string): Knex.Raw {
23
return this.knex.raw('DAYOFWEEK(??.??)', [table, column]);
26
hour(table: string, column: string): Knex.Raw {
27
return this.knex.raw('HOUR(??.??)', [table, column]);
30
minute(table: string, column: string): Knex.Raw {
31
return this.knex.raw('MINUTE(??.??)', [table, column]);
34
second(table: string, column: string): Knex.Raw {
35
return this.knex.raw('SECOND(??.??)', [table, column]);
38
count(table: string, column: string, options?: FnHelperOptions): Knex.Raw {
39
const collectionName = options?.originalCollectionName || table;
40
const type = this.schema.collections?.[collectionName]?.fields?.[column]?.type ?? 'unknown';
42
if (type === 'json') {
43
return this.knex.raw('JSON_LENGTH(??.??)', [table, column]);
46
if (type === 'alias') {
47
return this._relationalCount(table, column, options);
50
throw new Error(`Couldn't extract type from ${table}.${column}`);