Add: Optional DB SSH

This commit is contained in:
Donatas Kirda 2025-05-11 21:55:24 +03:00
parent 56c1c4ac76
commit 4d53448465
Signed by: bloodwiing
GPG Key ID: 63020D8D3F4A164F
2 changed files with 44 additions and 23 deletions

View File

@ -2,9 +2,13 @@ import { env } from '$lib/env';
import postgres from 'postgres'; import postgres from 'postgres';
import ssh2 from 'ssh2'; import ssh2 from 'ssh2';
// @ts-ignore /**
export const sql = postgres( * @returns {postgres.Options<{}>}
{ */
function getPostreConfig() {
if (env.SSH_ENABLE == 'true') {
// with ssh
return {
host: env.PG_HOST, host: env.PG_HOST,
port: parseInt(env.PG_PORT), port: parseInt(env.PG_PORT),
database: env.PG_DATABASE, database: env.PG_DATABASE,
@ -28,4 +32,20 @@ export const sql = postgres(
}) })
}) })
} }
} else {
// no ssh
return {
host: env.PG_HOST,
port: parseInt(env.PG_PORT),
database: env.PG_DATABASE,
username: env.PG_USERNAME,
password: env.PG_PASSWORD,
}
}
}
export const sql = postgres(
getPostreConfig()
); );

View File

@ -5,6 +5,7 @@ export type Env = {
PG_PORT: string, PG_PORT: string,
PG_DATABASE: string, PG_DATABASE: string,
SSH_ENABLE: string,
SSH_HOST: string, SSH_HOST: string,
SSH_PORT: string, SSH_PORT: string,
SSH_USERNAME: string, SSH_USERNAME: string,