directus

Форк
0
18 строк · 846.0 Байт
1
import type { Knex } from 'knex';
2
import { AutoSequenceHelper } from '../types.js';
3

4
export class AutoIncrementHelperPostgres extends AutoSequenceHelper {
5
	/**
6
	 * Resets the auto increment sequence based on the max value of the PK column.
7
	 * The sequence name is determined using a sub query.
8
	 *
9
	 * The table name value for getting the sequence name needs to be escaped explicitly,
10
	 * otherwise PostgreSQL would throw an error for capitalized table names saying "relation x does not exist".
11
	 */
12
	override async resetAutoIncrementSequence(table: string, column: string): Promise<Knex.Raw | void> {
13
		return await this.knex.raw(
14
			`WITH sequence_infos AS (SELECT pg_get_serial_sequence(?, ?) AS seq_name, MAX(??) as max_val FROM ??) SELECT SETVAL(seq_name, max_val) FROM sequence_infos;`,
15
			[`"${table}"`, column, column, table],
16
		);
17
	}
18
}
19

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

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

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

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