Skip to content

Use static variable for DATABASE_URL #398

@hyunbinseo

Description

@hyunbinseo

Is there a reason why the env.DATABASE_URL is dynamically imported?

This is the template generated with [email protected]:

// current
import { env } from '$env/dynamic/private';
import Database from 'better-sqlite3';
import { drizzle } from 'drizzle-orm/better-sqlite3';

if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
const client = new Database(env.DATABASE_URL);
export const db = drizzle(client);

This is what I've been using:

// proposal
import { DATABASE_URL } from '$env/static/private';
import Database from 'better-sqlite3';
import { drizzle } from 'drizzle-orm/better-sqlite3';

const client = new Database(DATABASE_URL);
export const db = drizzle(client);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions