diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-04 21:57:24 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-04 21:57:24 +0200 |
commit | e563aa25b43e55eb86e5119edb71b0ccf20102ff (patch) | |
tree | 13487ab459b896b10d9dba2a38d77445bc075836 /util/src | |
parent | Merge branch 'master' of https://github.com/fosscord/fosscord-server (diff) | |
download | server-e563aa25b43e55eb86e5119edb71b0ccf20102ff.tar.xz |
:construction: different db engines
Diffstat (limited to 'util/src')
-rw-r--r-- | util/src/util/Database.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/util/src/util/Database.ts b/util/src/util/Database.ts index ab7c70c5..369a403c 100644 --- a/util/src/util/Database.ts +++ b/util/src/util/Database.ts @@ -1,6 +1,6 @@ import path from "path"; import "reflect-metadata"; -import { Connection, createConnection, ValueTransformer } from "typeorm"; +import { Connection, createConnection } from "typeorm"; import * as Models from "../entities"; // UUID extension option is only supported with postgres @@ -8,18 +8,20 @@ import * as Models from "../entities"; var promise: Promise<any>; var dbConnection: Connection | undefined; +let dbConnectionString = process.env.DATABASE || path.join(process.cwd(), "database.db"); export function initDatabase() { if (promise) return promise; // prevent initalizing multiple times - console.log("[Database] connecting ..."); + const type = dbConnectionString.includes(":") ? dbConnectionString.split(":")[0]?.replace("+srv", "") : "sqlite"; + const isSqlite = type.includes("sqlite"); + + console.log(`[Database] connecting to ${type} db`); // @ts-ignore promise = createConnection({ - type: "sqlite", - database: path.join(process.cwd(), "database.db"), - // type: "postgres", - // url: "postgres://fosscord:wb94SmuURM2Syv&@localhost/fosscord", - // + type, + url: isSqlite ? undefined : dbConnectionString, + database: isSqlite ? dbConnectionString : undefined, entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"), synchronize: true, logging: false, |