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

[FEATURE]: Async Configuration #1187

Open
shellscape opened this issue Sep 7, 2023 · 3 comments
Open

[FEATURE]: Async Configuration #1187

shellscape opened this issue Sep 7, 2023 · 3 comments
Labels
enhancement New feature or request priority Will be worked on next

Comments

@shellscape
Copy link

Describe what you want

At present drizzle has a traditional constructor/initializer with literal configuration properties. e.g.

const pool = new Pool({ connectionString: process.env.DB_URL! });
drizzle(pool, { schema })

Now consider that our DB Url is located in a secret manager/store, which requires an async request to fetch.

const dbUrl = await getRemoteSecret('DB_URL');
const pool = new Pool({ connectionString: dbUrl });
drizzle(pool, { schema })

In ES module land, this works without issue. However, in Node-CJS land this does not work. Our only alternative is to export an async init method and use that wherever we'd like to access our database. That is quite common and normal for folks who are still working in CJS. There is a pattern that could be used to alleviate the need for an async init method - allowing for asyn configuration. Bundlers like Vite, Webpack, and Rollup all support async configs for this kind of purpose, so there is some prior art there. One such implementation might look like:

drizzle(async () => {
 const dbUrl = await getRemoteSecret('DB_URL');
 const pool = new Pool({ connectionString: dbUrl });

 return { client: pool, schema };
})

Given how the result of drizzle is typically used, that might require some fancy use of Proxy.

I noticed there were a few other issues open about top-level await and an older reverted commit which might be solved by this approach.

@jmls
Copy link

jmls commented Mar 22, 2024

does anyone have an idea on how to implement this ? I need to configure the db host based on an async call

@jbeckermanthrotle
Copy link

jbeckermanthrotle commented Apr 18, 2024

We're having the same exact issue! We've coded a work around, but it is not ideal and makes the app extremely slow. Is there a plan to allow for Async calls to inject our credentials like requested above?

@MDrooker
Copy link

MDrooker commented Jun 3, 2024

Any update on the thinking for this feature?

@L-Mario564 L-Mario564 added the priority Will be worked on next label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority Will be worked on next
Projects
None yet
Development

No branches or pull requests

5 participants