From 38668a07af1347ed719d9fade26e95aec30affef Mon Sep 17 00:00:00 2001 From: Harold Howe Date: Sat, 11 Mar 2023 15:28:42 -0600 Subject: [PATCH] Added missing dialects to fix ts compile with sequelize 6.29. Fixes #641. --- src/auto-builder.ts | 4 ++-- src/auto.ts | 4 ++-- src/dialects/dialects.ts | 13 ++++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/auto-builder.ts b/src/auto-builder.ts index 831f602e..53ef01f0 100644 --- a/src/auto-builder.ts +++ b/src/auto-builder.ts @@ -2,7 +2,7 @@ import _ from "lodash"; import { Dialect, QueryInterface, QueryTypes, Sequelize } from "sequelize"; import { AutoOptions } from "."; import { ColumnElementType, ColumnPrecision, DialectOptions, FKRow, FKSpec, TriggerCount } from "./dialects/dialect-options"; -import { dialects } from "./dialects/dialects"; +import { getDialect } from "./dialects/dialects"; import { Field, IndexSpec, Table, TableData } from "./types"; /** Queries the database and builds the tables, foreignKeys, indexes, and hasTriggerTables structures in TableData */ @@ -19,7 +19,7 @@ export class AutoBuilder { constructor(sequelize: Sequelize, options: AutoOptions) { this.sequelize = sequelize; this.queryInterface = this.sequelize.getQueryInterface(); - this.dialect = dialects[this.sequelize.getDialect() as Dialect]; + this.dialect = getDialect(this.sequelize.getDialect() as Dialect); this.includeTables = options.tables; this.skipTables = options.skipTables; this.schema = options.schema; diff --git a/src/auto.ts b/src/auto.ts index cd44e58c..18a9432c 100644 --- a/src/auto.ts +++ b/src/auto.ts @@ -5,7 +5,7 @@ import { AutoBuilder } from "./auto-builder"; import { AutoGenerator } from "./auto-generator"; import { AutoRelater } from "./auto-relater"; import { AutoWriter } from "./auto-writer"; -import { dialects } from "./dialects/dialects"; +import { getDialect } from "./dialects/dialects"; import { AutoOptions, TableData } from "./types"; export class SequelizeAuto { @@ -72,7 +72,7 @@ export class SequelizeAuto { } generate(tableData: TableData) { - const dialect = dialects[this.sequelize.getDialect() as Dialect]; + const dialect = getDialect(this.sequelize.getDialect() as Dialect); const generator = new AutoGenerator(tableData, dialect, this.options); return generator.generateText(); } diff --git a/src/dialects/dialects.ts b/src/dialects/dialects.ts index a86b9535..019cf6e8 100644 --- a/src/dialects/dialects.ts +++ b/src/dialects/dialects.ts @@ -5,10 +5,21 @@ import { sqliteOptions } from "./sqlite"; import { DialectOptions } from "./dialect-options"; import { Dialect } from "sequelize"; -export const dialects: { [name in Dialect]: DialectOptions } = { +const dialects: { [name in Dialect]: DialectOptions | null } = { + db2: null, + oracle: null, + snowflake: null, mssql: mssqlOptions, mysql: mysqlOptions, mariadb: mysqlOptions, postgres: postgresOptions, sqlite: sqliteOptions }; + +export function getDialect(dialectName: Dialect) : DialectOptions { + const result = dialects[dialectName]; + if(!result) { + throw new Error(`Dialect not available for ${dialectName}`); + } + return result as DialectOptions; +}