Skip to content

Commit 38668a0

Browse files
committed
Added missing dialects to fix ts compile with sequelize 6.29. Fixes sequelize#641.
1 parent 4197141 commit 38668a0

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/auto-builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from "lodash";
22
import { Dialect, QueryInterface, QueryTypes, Sequelize } from "sequelize";
33
import { AutoOptions } from ".";
44
import { ColumnElementType, ColumnPrecision, DialectOptions, FKRow, FKSpec, TriggerCount } from "./dialects/dialect-options";
5-
import { dialects } from "./dialects/dialects";
5+
import { getDialect } from "./dialects/dialects";
66
import { Field, IndexSpec, Table, TableData } from "./types";
77

88
/** Queries the database and builds the tables, foreignKeys, indexes, and hasTriggerTables structures in TableData */
@@ -19,7 +19,7 @@ export class AutoBuilder {
1919
constructor(sequelize: Sequelize, options: AutoOptions) {
2020
this.sequelize = sequelize;
2121
this.queryInterface = this.sequelize.getQueryInterface();
22-
this.dialect = dialects[this.sequelize.getDialect() as Dialect];
22+
this.dialect = getDialect(this.sequelize.getDialect() as Dialect);
2323
this.includeTables = options.tables;
2424
this.skipTables = options.skipTables;
2525
this.schema = options.schema;

src/auto.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AutoBuilder } from "./auto-builder";
55
import { AutoGenerator } from "./auto-generator";
66
import { AutoRelater } from "./auto-relater";
77
import { AutoWriter } from "./auto-writer";
8-
import { dialects } from "./dialects/dialects";
8+
import { getDialect } from "./dialects/dialects";
99
import { AutoOptions, TableData } from "./types";
1010

1111
export class SequelizeAuto {
@@ -72,7 +72,7 @@ export class SequelizeAuto {
7272
}
7373

7474
generate(tableData: TableData) {
75-
const dialect = dialects[this.sequelize.getDialect() as Dialect];
75+
const dialect = getDialect(this.sequelize.getDialect() as Dialect);
7676
const generator = new AutoGenerator(tableData, dialect, this.options);
7777
return generator.generateText();
7878
}

src/dialects/dialects.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@ import { sqliteOptions } from "./sqlite";
55
import { DialectOptions } from "./dialect-options";
66
import { Dialect } from "sequelize";
77

8-
export const dialects: { [name in Dialect]: DialectOptions } = {
8+
const dialects: { [name in Dialect]: DialectOptions | null } = {
9+
db2: null,
10+
oracle: null,
11+
snowflake: null,
912
mssql: mssqlOptions,
1013
mysql: mysqlOptions,
1114
mariadb: mysqlOptions,
1215
postgres: postgresOptions,
1316
sqlite: sqliteOptions
1417
};
18+
19+
export function getDialect(dialectName: Dialect) : DialectOptions {
20+
const result = dialects[dialectName];
21+
if(!result) {
22+
throw new Error(`Dialect not available for ${dialectName}`);
23+
}
24+
return result as DialectOptions;
25+
}

0 commit comments

Comments
 (0)