Support runtime env expansion for database config
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Describe the feature
Currently database connector options are embedded into the build output. It means value such as database credentials may be bundled.
We need a way to get the database config dynamically at runtime. Nitro now supports runtime config so we can get a method for free.
const config = {
url: useRuntimeConfig().database.url || bundledOptions.url
}
Inspired by env expansion, we also have a more flexible solution:
export default defineConfig({
database: {
default: {
connector: "postgresql",
options: {
url: "{{DATABASE_URL}}",
},
},
},
});
For non-string options such as port, we may need type metadata from db0 since environment variables are resolved as strings and we need to convert to number.
Should we consider only converting the required keys? Perhaps we also need db0 to provide the list of keys.
Additional information
- Would you be willing to help implement this feature?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the useRuntimeConfig() path and the database connector options configured through defineConfig, then compare the linked Nitro env-expansion behavior. Done means database values can be resolved at runtime without bundling credentials, bundled options remain a fallback, and non-string values such as ports are converted correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100