Skip to content

Support runtime env expansion for database config #4545

Description

@Teages

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions