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

Add driver back to drizzle.config #422

Closed
lirc571 opened this issue May 21, 2024 · 11 comments
Closed

Add driver back to drizzle.config #422

lirc571 opened this issue May 21, 2024 · 11 comments
Milestone

Comments

@lirc571
Copy link

lirc571 commented May 21, 2024

With the recent updates in drizzle-kit, it is now impossible to select a driver when multiple drivers for the same dialect are installed.

E.g. in a mono-repo setup, I have both @libsql/client and better-sqlite3 installed (used in different packages), but I can no longer use better-sqlite3 because @libsql/client is selected by default when dialect is set to sqlite.

@rghamilton3
Copy link

+1

@AlexBlokh
Copy link
Contributor

@lirc571 @rghamilton3 please let me know what are the issues with that, those 2 drivers should be 100% compatible with each other

@lirc571
Copy link
Author

lirc571 commented May 23, 2024

@AlexBlokh I can no longer use a sqlite db file with the libsql driver:

LibsqlError: URL_INVALID: The URL is not in a valid format

The config looks like:

import { defineConfig } from 'drizzle-kit'
export default defineConfig({
 schema: "./schema.ts",
  dialect: 'sqlite',
  dbCredentials: {
    url: "data/my_db.db",
  },
  verbose: true,
  strict: true,
})

@rghamilton3
Copy link

@AlexBlokh you can disregard me. My issue was with a typo in the generated schema and a table name. I'm not sure if I some how messed up the generated schema without noticing (most likely) but everything works now. I'll open a new issue if that generated schema issue is repeatable.

@greg-hammond
Copy link

@AlexBlokh I documented this same issue in #399 .

The current logic in connectToSQLite preferentially selects @libsql/client based solely on its presence, rather than by inspecting the config directly.

@AlexBlokh
Copy link
Contributor

@lirc571 I've added automatic prefixing of file: for libSQL and remove it automatically for better-sqlite3
so as of next release there should be no interop issues

just so we're on the same page - here's the reasoning behind this patch, thus we wanna omit any other driver added to the config, unless it's truly necessary

@lirc571
Copy link
Author

lirc571 commented May 27, 2024

@AlexBlokh I agree that making driver optional would make the config look simpler as mentioned in that post, but to me it makes more sense to keep driver and remove dialect because dialect can be inferred from driver directly, which is what knex seems to be doing according to their doc.

I am also fine with making driver optional, but in the current version driver is completely removed?

When there are multiple drivers installed for the same dialect, I would like to specify the driver in the config explicitly instead of relying on some black box mechanisms to determine which one to use. What if 2 drivers have the same dbCredentials and I want to use them in different packages in a monorepo?

@AlexBlokh
Copy link
Contributor

@lirc571 please let me know the use case for having 2 drivers and occasionally choose particular one for different scenarios(taking in count we gonna make the cross compatible in all scenarios and if not - extract to driver)

removing dialect is not an option for us, first - it's going to be harder for newcomers/less experienced developers, second - for a majority of commands driver is optional, as opposed to dialect

@lirc571
Copy link
Author

lirc571 commented May 27, 2024

@lirc571 please let me know the use case for having 2 drivers and occasionally choose particular one for different scenarios(taking in count we gonna make the cross compatible in all scenarios and if not - extract to driver)

In a monorepo setup, we can have different applications that use different drivers. Let's say existing apps are all using the postgres driver, but I want to create a new app that uses the pg driver, I won't want all existing apps to automatically switch to the pg driver without me changing their configurations, just because pg is now installed.

@AlexBlokh AlexBlokh added this to the v0.21.5 milestone May 27, 2024
@AndriiSherman
Copy link
Member

fixed in drizzle-kit@0.22.0

@lirc571
Copy link
Author

lirc571 commented Jun 4, 2024

Hi @AndriiSherman @AlexBlokh, according to the changelog, it seems that drizzle-kit is still choosing the driver for us and there is no option to select a driver of our choice, so it does not solve the root issue @greg-hammond and I raised: we would like to have an option to specify the driver (the driver option can be optional, but should not be removed), so that the use case below can be satisfied.

In a monorepo setup, we can have different applications that use different drivers. Let's say existing apps are all using the postgres driver, but I want to create a new app that uses the pg driver, I won't want all existing apps to automatically switch to the pg driver without me changing their configurations, just because pg is now installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants