Set databaseURL as env variable in client file
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",
};
En variable already exists and works, codegen is the only place where we would want to remove it
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"
}
}
}