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

MSSQL Support Fully Qualified Table Names #1203

Open
chuck-flowers opened this issue Oct 31, 2024 · 5 comments
Open

MSSQL Support Fully Qualified Table Names #1203

chuck-flowers opened this issue Oct 31, 2024 · 5 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request mssql Related to MS SQL Server (MSSQL) typescript Related to Typescript wontfix This will not be worked on

Comments

@chuck-flowers
Copy link

In MSSQL it is possible to reference tables from multiple databases within a single connection. This is accomplished by using a 3-part identifier like the following: MyDatabase.dbo.MyTable.

It appears that kysely doesn't currently support this. Is there a technical reason that prevents this from being supported or has it not yet been requested?

I'm more than happy to try to implement it if you're open to having the feature included in the project. After looking at the code, my first idea is to add an optional database property to the SchemableIdentifier type and support properly stringifying it in the MssqlCompiler if that property is present. If there's something I'm overlooking please let me know.

@koskimas
Copy link
Member

koskimas commented Oct 31, 2024

This has come up, but implementing support for this would complicate the types a lot. It'd make the types more complex and considerably slower to compile for everyone. Not just mssql users.

You are overlooking types. The SQL part of it is relatively straight forward to implement. The types definitely aren't.

@chuck-flowers
Copy link
Author

I totally understand.

Since this has come up before, are there any recommended work arounds? Unfortunately the way the DBs are organized for this application requires doing cross-db joins.

@igalklebanov
Copy link
Member

igalklebanov commented Oct 31, 2024

Hey 👋

A possible workaround would be:

  1. omitting dbo from the database interface table names.
  2. a plugin that maps to/from 3 dot references from/to 2 dot references.

So when you're writing your queries, you don't write dbo, just [dbname].[tablename], but [dbname].dbo.[tablename] gets compiled.

@igalklebanov igalklebanov added duplicate This issue or pull request already exists enhancement New feature or request wontfix This will not be worked on mssql Related to MS SQL Server (MSSQL) typescript Related to Typescript labels Oct 31, 2024
@chuck-flowers
Copy link
Author

chuck-flowers commented Oct 31, 2024

Thank you for the suggestions. That sounds like a workable solution on my end.

I'll close this issue now

@chuck-flowers
Copy link
Author

chuck-flowers commented Nov 2, 2024

@igalklebanov I took a stab at creating the plugin as you described but I'm running into another issue now. After mapping from 2 to 3, it seems that kysely is double quoting the result to escape the extra dot. Is there a way to get kysely to not escape the table name with double quotes?

EDIT: Nevermind, I was able to accomplish it by extending/overriding the MssqlQueryCompiler. I was able to get a query to execute successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request mssql Related to MS SQL Server (MSSQL) typescript Related to Typescript wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants