/**
 * Provides a raw better-sqlite3 Database instance for use in services that
 * need direct SQL access (not via Drizzle ORM).
 */
import Database from 'better-sqlite3';
import { env } from '$env/dynamic/private';

let _client: Database.Database | null = null;

export function getClient(): Database.Database {
	if (!_client) {
		if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
		_client = new Database(env.DATABASE_URL);
		_client.pragma('journal_mode = WAL');
		_client.pragma('foreign_keys = ON');
	}
	return _client;
}
