From b936c8af04d4a7cf87fb6ffebf20c5893811ede3 Mon Sep 17 00:00:00 2001 From: Max Polsky Date: Tue, 5 Dec 2023 19:10:23 +0200 Subject: [PATCH] Add support for time and date columns in BigQuery, MSSQL, MySQL, and Postgres capabilities --- .../src/bigquery_capabilities.ts | 2 ++ .../src/sql_schema_translator.spec.ts | 33 ++++++++++++------- .../src/sql_schema_translator.ts | 14 ++++++-- .../src/mysql_capabilities.ts | 2 ++ .../src/postgres_capabilities.ts | 2 ++ 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/libs/external-db-bigquery/src/bigquery_capabilities.ts b/libs/external-db-bigquery/src/bigquery_capabilities.ts index 72c1f55de..69782a418 100644 --- a/libs/external-db-bigquery/src/bigquery_capabilities.ts +++ b/libs/external-db-bigquery/src/bigquery_capabilities.ts @@ -18,4 +18,6 @@ export const ColumnsCapabilities = { image: { sortable: false, columnQueryOperators: [] }, object: { sortable: false, columnQueryOperators: [] }, datetime: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + time: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + date: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, } diff --git a/libs/external-db-mssql/src/sql_schema_translator.spec.ts b/libs/external-db-mssql/src/sql_schema_translator.spec.ts index 311142309..c876138bc 100644 --- a/libs/external-db-mssql/src/sql_schema_translator.spec.ts +++ b/libs/external-db-mssql/src/sql_schema_translator.spec.ts @@ -67,9 +67,18 @@ describe('Sql Schema Column Translator', () => { }) describe('string fields', () => { - test('string', () => { - expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string' }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2048)`) - }) + + test.each([ + 'string', + 'richcontent', + 'image', + 'video', + 'audio', + 'document', + 'language', + ])('text %s', (subtype) => { + expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2048)`) + }) test('string with length', () => { expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string', precision: '2055' }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2055)`) @@ -86,12 +95,6 @@ describe('Sql Schema Column Translator', () => { test('text large', () => { expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'large' }) ).toEqual(`${escapeId(ctx.fieldName)} TEXT`) }) - - test('text language', () => { - expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'language' }) ).toEqual(`${escapeId(ctx.fieldName)} TEXT`) - }) - - }) describe('other fields', () => { @@ -127,10 +130,16 @@ describe('Sql Schema Column Translator', () => { }) describe('date time fields', () => { + test('time', () => { + expect( env.schemaTranslator.translateType('TIME') ).toEqual('time') + }) + test('date', () => { - ['DATE', 'DATETIME', 'DATETIME2', 'TIME', 'DATETIMEOFFSET', 'SMALLDATETIME'].forEach(t => { - expect( env.schemaTranslator.translateType(t) ).toEqual('datetime') - }) + expect( env.schemaTranslator.translateType('DATE') ).toEqual('date') + }) + + test.each([ 'DATETIME', 'DATETIME2', 'DATETIMEOFFSET', 'SMALLDATETIME'])('%s', (t) => { + expect( env.schemaTranslator.translateType(t) ).toEqual('datetime') }) }) diff --git a/libs/external-db-mssql/src/sql_schema_translator.ts b/libs/external-db-mssql/src/sql_schema_translator.ts index 0f268f426..ddf26cd35 100644 --- a/libs/external-db-mssql/src/sql_schema_translator.ts +++ b/libs/external-db-mssql/src/sql_schema_translator.ts @@ -18,11 +18,14 @@ export default class SchemaColumnTranslator { case 'decimal': case 'numeric': return 'number' - + + case 'time': + return 'time' case 'date': + return 'date' + case 'datetime': case 'datetime2': - case 'time': case 'datetimeoffset': case 'smalldatetime': return 'datetime' @@ -83,12 +86,17 @@ export default class SchemaColumnTranslator { return 'SMALLDATETIME' case 'text_string': + case 'text_richcontent': + case 'text_image': + case 'text_video': + case 'text_audio': + case 'text_document': + case 'text_language': return `VARCHAR${this.parseLength(precision)}` case 'text_small': case 'text_medium': case 'text_large': - case 'text_language': return 'TEXT' diff --git a/libs/external-db-mysql/src/mysql_capabilities.ts b/libs/external-db-mysql/src/mysql_capabilities.ts index 7b22111e9..7250e9510 100644 --- a/libs/external-db-mysql/src/mysql_capabilities.ts +++ b/libs/external-db-mysql/src/mysql_capabilities.ts @@ -18,4 +18,6 @@ export const ColumnsCapabilities = { image: { sortable: false, columnQueryOperators: [] }, object: { sortable: false, columnQueryOperators: [eq, ne, string_contains, string_begins, string_ends, include, gt, gte, lt, lte] }, datetime: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + time: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + date: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, } diff --git a/libs/external-db-postgres/src/postgres_capabilities.ts b/libs/external-db-postgres/src/postgres_capabilities.ts index 04a414516..9ae7f2a7c 100644 --- a/libs/external-db-postgres/src/postgres_capabilities.ts +++ b/libs/external-db-postgres/src/postgres_capabilities.ts @@ -16,4 +16,6 @@ export const ColumnsCapabilities = { image: { sortable: false, columnQueryOperators: [] }, object: { sortable: false, columnQueryOperators: [eq, ne, string_contains, string_begins, string_ends, include, gt, gte, lt, lte] }, datetime: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + time: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + date: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, }