Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing dialects to fix ts compile with sequelize 6.29. #642

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}