Skip to content

Commit

Permalink
fix: add fallback values to dialect type and database url for build t…
Browse files Browse the repository at this point in the history
…o succeed (#49)
  • Loading branch information
AyushSehrawat authored Aug 1, 2024
1 parent 840906e commit 8ea57f0
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/lib/server/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@ import pkg from 'pg';
const { Pool } = pkg;

let dialect;
const dialectType = env.DIALECT || 'sqlite';
const databaseUrl = env.DATABASE_URL || '';

if (env.DIALECT) {
switch (env.DIALECT) {
case 'sqlite':
dialect = new SqliteDialect({
database: new SQLite(env.DATABASE_URL)
});
break;
case 'postgres':
dialect = new PostgresDialect({
pool: new Pool({
connectionString: env.DATABASE_URL
})
});
break;
}
switch (dialectType) {
case 'sqlite':
dialect = new SqliteDialect({
database: new SQLite(databaseUrl)
});
break;
case 'postgres':
dialect = new PostgresDialect({
pool: new Pool({
connectionString: databaseUrl
})
});
break;
}

export const db = new Kysely<DB>({
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
dialect
});

0 comments on commit 8ea57f0

Please sign in to comment.