@@ -36,6 +36,7 @@
|
|||||||
"$fresh/": "https://deno.land/x/fresh@1.7.3/",
|
"$fresh/": "https://deno.land/x/fresh@1.7.3/",
|
||||||
"std/": "https://deno.land/std@0.224.0/",
|
"std/": "https://deno.land/std@0.224.0/",
|
||||||
"$std/": "https://deno.land/std@0.224.0/",
|
"$std/": "https://deno.land/std@0.224.0/",
|
||||||
|
"postgres": "https://deno.land/x/postgres@v0.19.3/mod.ts",
|
||||||
"preact": "https://esm.sh/preact@10.23.2",
|
"preact": "https://esm.sh/preact@10.23.2",
|
||||||
"preact/": "https://esm.sh/preact@10.23.2/",
|
"preact/": "https://esm.sh/preact@10.23.2/",
|
||||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.3.0",
|
"@preact/signals": "https://esm.sh/*@preact/signals@1.3.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
website:
|
website:
|
||||||
image: ghcr.io/bewcloud/bewcloud:v2.2.2
|
image: ghcr.io/bewcloud/bewcloud:v2.2.3
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:8000:8000
|
- 127.0.0.1:8000:8000
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Client } from 'https://deno.land/x/postgres@v0.19.3/mod.ts';
|
import { Client } from 'postgres';
|
||||||
import 'std/dotenv/load.ts';
|
import 'std/dotenv/load.ts';
|
||||||
|
|
||||||
const POSTGRESQL_HOST = Deno.env.get('POSTGRESQL_HOST') || '';
|
const POSTGRESQL_HOST = Deno.env.get('POSTGRESQL_HOST') || '';
|
||||||
@@ -21,8 +21,14 @@ const tls = POSTGRESQL_CAFILE
|
|||||||
|
|
||||||
export default class Database {
|
export default class Database {
|
||||||
protected db?: Client;
|
protected db?: Client;
|
||||||
|
protected throwOnConnectionError?: boolean;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
{ connectNow = false, throwOnConnectionError = false }: { connectNow?: boolean; throwOnConnectionError?: boolean } =
|
||||||
|
{},
|
||||||
|
) {
|
||||||
|
this.throwOnConnectionError = throwOnConnectionError;
|
||||||
|
|
||||||
constructor(connectNow = false) {
|
|
||||||
if (connectNow) {
|
if (connectNow) {
|
||||||
this.connectToPostgres();
|
this.connectToPostgres();
|
||||||
}
|
}
|
||||||
@@ -64,6 +70,10 @@ export default class Database {
|
|||||||
console.log('Failed to connect to Postgres!');
|
console.log('Failed to connect to Postgres!');
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
|
if (this.throwOnConnectionError) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
// This allows tests (and the app) to work even if Postgres is not available
|
// This allows tests (and the app) to work even if Postgres is not available
|
||||||
const mockPostgresClient = {
|
const mockPostgresClient = {
|
||||||
queryObject: () => {
|
queryObject: () => {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const migrationsDirectoryPath = `${Deno.cwd()}/db-migrations`;
|
|||||||
|
|
||||||
const migrationsDirectory = Deno.readDir(migrationsDirectoryPath);
|
const migrationsDirectory = Deno.readDir(migrationsDirectoryPath);
|
||||||
|
|
||||||
const db = new Database();
|
const db = new Database({ throwOnConnectionError: true });
|
||||||
|
|
||||||
interface Migration {
|
interface Migration {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user