export function detectProvider(url) {
    if (url.startsWith('file:') || url.startsWith('sqlite:') || url === ':memory:')
        return 'sqlite';
    if (url.startsWith('mysql://'))
        return 'mysql';
    return 'postgresql';
}
export async function createDatabaseClient(config) {
    switch (config.provider) {
        case 'postgresql': {
            const { createPostgresAdapter } = await import('./adapters/postgres.js');
            return createPostgresAdapter({
                url: config.url,
                directUrl: config.directUrl,
                poolSize: config.poolSize,
            });
        }
        case 'sqlite': {
            const { createSQLiteAdapter } = await import('./adapters/sqlite.js');
            return createSQLiteAdapter({
                filename: config.url.replace(/^file:|^sqlite:/i, ''),
            });
        }
        case 'mysql': {
            const { createMySQLAdapter } = await import('./adapters/mysql.js');
            return createMySQLAdapter({ url: config.url });
        }
        default:
            throw new Error(`Unsupported database provider: ${config.provider}`);
    }
}
export async function createDatabaseClientFromEnv() {
    const url = process.env.DATABASE_URL;
    if (!url)
        throw new Error('DATABASE_URL environment variable is required');
    const provider = detectProvider(url);
    return createDatabaseClient({
        provider,
        url,
        directUrl: process.env.DIRECT_DATABASE_URL,
    });
}
//# sourceMappingURL=create-adapter.js.map