|
1 | 1 | /* eslint-disable sonarjs/no-duplicate-string */
|
2 | 2 | import { Logger } from '@nestjs/common';
|
3 |
| -import type { IFilter, ILookupOptionsVo, ISortItem } from '@teable/core'; |
| 3 | +import type { FieldType, IFilter, ILookupOptionsVo, ISortItem } from '@teable/core'; |
4 | 4 | import { DriverClient } from '@teable/core';
|
5 | 5 | import type { PrismaClient } from '@teable/db-main-prisma';
|
6 | 6 | import type { IAggregationField, ISearchIndexByQueryRo } from '@teable/openapi';
|
@@ -75,6 +75,16 @@ export class PostgresProvider implements IDbProvider {
|
75 | 75 | return res[0].exists;
|
76 | 76 | }
|
77 | 77 |
|
| 78 | + checkTableExist(tableName: string): string { |
| 79 | + const [schemaName, dbTableName] = this.splitTableName(tableName); |
| 80 | + return this.knex |
| 81 | + .raw( |
| 82 | + 'SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = ? AND table_name = ?) AS exists', |
| 83 | + [schemaName, dbTableName] |
| 84 | + ) |
| 85 | + .toQuery(); |
| 86 | + } |
| 87 | + |
78 | 88 | renameColumn(tableName: string, oldName: string, newName: string): string[] {
|
79 | 89 | return this.knex.schema
|
80 | 90 | .alterTable(tableName, (table) => {
|
@@ -424,20 +434,29 @@ export class PostgresProvider implements IDbProvider {
|
424 | 434 | lookupOptionsQuery(optionsKey: keyof ILookupOptionsVo, value: string): string {
|
425 | 435 | return this.knex('field')
|
426 | 436 | .select({
|
| 437 | + tableId: 'table_id', |
427 | 438 | id: 'id',
|
| 439 | + type: 'type', |
| 440 | + name: 'name', |
428 | 441 | lookupOptions: 'lookup_options',
|
429 | 442 | })
|
| 443 | + .whereNull('deleted_time') |
430 | 444 | .whereRaw(`lookup_options::json->>'${optionsKey}' = ?`, [value])
|
431 | 445 | .toQuery();
|
432 | 446 | }
|
433 | 447 |
|
434 |
| - optionsQuery(optionsKey: string, value: string): string { |
| 448 | + optionsQuery(type: FieldType, optionsKey: string, value: string): string { |
435 | 449 | return this.knex('field')
|
436 | 450 | .select({
|
| 451 | + tableId: 'table_id', |
437 | 452 | id: 'id',
|
| 453 | + type: 'type', |
| 454 | + name: 'name', |
438 | 455 | options: 'options',
|
439 | 456 | })
|
| 457 | + .whereNull('deleted_time') |
440 | 458 | .whereRaw(`options::json->>'${optionsKey}' = ?`, [value])
|
| 459 | + .where('type', type) |
441 | 460 | .toQuery();
|
442 | 461 | }
|
443 | 462 | }
|
0 commit comments