Skip to content

Commit

Permalink
Added missing dialects to fix ts compile with sequelize 6.29. Fixes #641
Browse files Browse the repository at this point in the history
.
  • Loading branch information
hhowe29 committed Mar 11, 2023
1 parent 4197141 commit 38668a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/auto-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand Down
13 changes: 12 additions & 1 deletion src/dialects/dialects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 38668a0

Please sign in to comment.