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

Set databaseURL as env variable in client file #1440

Open
kostasb opened this issue Apr 15, 2024 · 2 comments
Open

Set databaseURL as env variable in client file #1440

kostasb opened this issue Apr 15, 2024 · 2 comments
Labels
bug Something isn't working needs-triage

Comments

@kostasb
Copy link
Contributor

kostasb commented Apr 15, 2024

The generated client file contains the actual database url, which raises concerns with committing the file to public repos and having to always generate it via the CLI for deployments.

Replacing it with an env variable would address these.

const defaultOptions = {
  databaseURL: "https://myws-123456.eu-west-1.xata.sh/db/mydb",
};
@kostasb kostasb added the bug Something isn't working label Apr 15, 2024
@SferaDev
Copy link
Member

SferaDev commented Apr 15, 2024

En variable already exists and works, codegen is the only place where we would want to remove it

@kerimhudson
Copy link

kerimhudson commented Apr 25, 2024

I started working on this, hope that's alright as it's especially as it's something I've definitely been after using as well.

At the moment I've adopted using XATA_DATABASE_URL as the environment variable, but we likely have to consider other projects such as Next.JS or Vite which require prefixed environment variables.

We could look to add in custom framework settings, or potentially even trying to guess at what framework a project is using (looking for a next.config file for example). Although that might be making this too large a piece of work for now.

Or would it be better to just provide an option in the configuration to handle setting your own name for the environment variables. Something like:

{
  "databaseURL": "",
  "codegen": {
    "output": "src/xata.ts",
    "env": {
      "API_KEY": "XATA_API_KEY",
      "DATABASE_URL": "XATA_DATABASE_URL"
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants