directus

Форк
0
52 строки · 1.5 Кб
1
import type { Knex } from 'knex';
2
import type { FnHelperOptions } from '../types.js';
3
import { FnHelper } from '../types.js';
4

5
export class FnHelperMySQL extends FnHelper {
6
	year(table: string, column: string): Knex.Raw {
7
		return this.knex.raw('YEAR(??.??)', [table, column]);
8
	}
9

10
	month(table: string, column: string): Knex.Raw {
11
		return this.knex.raw('MONTH(??.??)', [table, column]);
12
	}
13

14
	week(table: string, column: string): Knex.Raw {
15
		return this.knex.raw('WEEK(??.??)', [table, column]);
16
	}
17

18
	day(table: string, column: string): Knex.Raw {
19
		return this.knex.raw('DAYOFMONTH(??.??)', [table, column]);
20
	}
21

22
	weekday(table: string, column: string): Knex.Raw {
23
		return this.knex.raw('DAYOFWEEK(??.??)', [table, column]);
24
	}
25

26
	hour(table: string, column: string): Knex.Raw {
27
		return this.knex.raw('HOUR(??.??)', [table, column]);
28
	}
29

30
	minute(table: string, column: string): Knex.Raw {
31
		return this.knex.raw('MINUTE(??.??)', [table, column]);
32
	}
33

34
	second(table: string, column: string): Knex.Raw {
35
		return this.knex.raw('SECOND(??.??)', [table, column]);
36
	}
37

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';
41

42
		if (type === 'json') {
43
			return this.knex.raw('JSON_LENGTH(??.??)', [table, column]);
44
		}
45

46
		if (type === 'alias') {
47
			return this._relationalCount(table, column, options);
48
		}
49

50
		throw new Error(`Couldn't extract type from ${table}.${column}`);
51
	}
52
}
53

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.