Skip to content

Commit

Permalink
Merge pull request #2 from mjbergman92/bug-mssql-driver-failing-conne…
Browse files Browse the repository at this point in the history
…ction-and-queries

MS SQL Server Driver Bug Fixes to Generate Schema Successfully
  • Loading branch information
thrownullexception authored May 15, 2024
2 parents e374caf + 2f1e903 commit bf23e89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/drivers/MssqlDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default class MssqlDriver extends AbstractDriver {
}>(
`SELECT TABLE_SCHEMA,TABLE_NAME, table_catalog as "DB_NAME" FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${MssqlDriver.buildEscapedObjectList(
schemas
)}) AND TABLE_CATALOG = ${this.connectionOptions.database}`
this.connectionOptions.schemaNames || ["dbo"]
)}) AND TABLE_CATALOG = '${this.connectionOptions.database}'`
);

const ret: Entity[] = [] as Entity[];
Expand Down Expand Up @@ -68,10 +68,10 @@ export default class MssqlDriver extends AbstractDriver {
LEFT JOIN (SELECT tc.TABLE_SCHEMA,tc.TABLE_NAME,cu.COLUMN_NAME,COUNT(1) AS cnt FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc inner join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu on cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME where tc.CONSTRAINT_TYPE = 'UNIQUE' GROUP BY tc.TABLE_SCHEMA,tc.TABLE_NAME,cu.COLUMN_NAME) AS tc
on tc.TABLE_NAME = c.TABLE_NAME and tc.COLUMN_NAME = c.COLUMN_NAME and tc.TABLE_SCHEMA=c.TABLE_SCHEMA
where c.TABLE_SCHEMA in (${MssqlDriver.buildEscapedObjectList(
schemas
)}) AND c.TABLE_CATALOG = ${
this.connectionOptions.schemaNames || ["dbo"]
)}) AND c.TABLE_CATALOG = '${
this.connectionOptions.database
} order by ordinal_position
}' order by ordinal_position
`
);
entities.forEach((ent) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const SupportedDataSourceToKnexClientMap: Record<
Partial<RDMSSources>,
string
> = {
mssql: "tedious",
mssql: "mssql",
postgres: "pg",
mysql: "mysql2",
sqlite: "better-sqlite3",
Expand Down

0 comments on commit bf23e89

Please sign in to comment.