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

allow passing custom connection instance to the connectors #19

Open
1 task
Hebilicious opened this issue Jun 30, 2023 · 5 comments
Open
1 task

allow passing custom connection instance to the connectors #19

Hebilicious opened this issue Jun 30, 2023 · 5 comments

Comments

@Hebilicious
Copy link
Member

Hebilicious commented Jun 30, 2023

Describe the feature

Db0 scope seems to be to provide a connector for every SQL-like language out there, as well as a wrapper around popular ORM.
I think we should consider letting the user initialise the client however he see fits, and pass the client instance to the connector.
If we do provide every single client, we endup having to manage and take care of many depedencies that we do not control, and we run into the problems where someone want to use the client without db0 and has to create two of them, or we have to expose the client etc

We could document how to install and initialise the client for each connector.

Additional information

  • Would you be willing to help implement this feature?
@pi0
Copy link
Member

pi0 commented Jun 30, 2023

Clients come as optional dependencies with each connector. Can you elaborate more what do you mean by client exactly and how we can avoid using them to implement connector? :)

Copy link
Member Author

You can see an example of such an approach with the Lucia adapters (I'm familiar with it as I've recently made an unstorage adapter for Lucia).
Basically we'd accept the client instance and then use the types to do the logic: https://github.com/pilcrowOnPaper/lucia/blob/main/packages/adapter-sqlite/src/drivers/better-sqlite3.ts

import { createDB, sql } from "db0";
import sqlite from "better-sqlite3";
import connector from "db0/connectors/better-sqlite3";
// or import { connectorSqlite3 } from "db0" 
const db = createDB(connector({ driver: sqlite("test/main.db")}))

@pi0
Copy link
Member

pi0 commented Jul 3, 2023

I am fine with supporting generic drivers that accept client instances for advanced usage that would be a nice idea.

But it takes away all possible zero config experience with nitro. This is how both unstorage and db0 are designed for to be simple and ship best practices with integration (similar how Nuxt itself integrated Vue..)

Copy link
Member Author

You're right, it would make sense to do it like with unstorage. I would be satisfied if we accepted an optional client instance for each driver.

@pi0
Copy link
Member

pi0 commented Jul 3, 2023

PR welcome to add support for current connectors :)

@pi0 pi0 changed the title [suggestion] do not ship the db clients allow passing custom connection instance to the connectors Jul 3, 2023
@pi0 pi0 added the enhancement label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants