diff --git a/.env.example b/.env.example index 3da7bc4..7070ead 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ +DB_TYPE = (mysql|sqlite|...) DB_HOST = database_host DB_NAME = database_name DB_USERNAME = database_username diff --git a/src/data-source.ts b/src/data-source.ts index 998f766..8cab226 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -1,7 +1,7 @@ import "dotenv/config"; import "reflect-metadata"; import { DataSource } from "typeorm"; -import { DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME } from "./env.defaults"; +import { DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_TYPE } from "./env.defaults"; import { user } from "./entity/user"; import { refresh } from "./entity/refresh"; @@ -14,7 +14,7 @@ import { Invite1724579024939 } from "./migrations/1724579024939-invite"; import { Permissions1724661484664 } from "./migrations/1724661484664-permissions"; const dataSource = new DataSource({ - type: "mysql", + type: DB_TYPE as any, host: process.env.NODE_ENV || process.env.DBMODE ? "localhost" : DB_HOST, port: 3306, username: DB_USERNAME, diff --git a/src/env.defaults.ts b/src/env.defaults.ts index 0422e88..82f5b75 100644 --- a/src/env.defaults.ts +++ b/src/env.defaults.ts @@ -1,6 +1,7 @@ import "dotenv/config"; import ms from "ms"; +export const DB_TYPE = process.env.DB_TYPE ?? "mysql"; export const DB_HOST = process.env.DB_HOST ?? ""; export const DB_NAME = process.env.DB_NAME ?? ""; export const DB_USERNAME = process.env.DB_USERNAME ?? ""; @@ -21,6 +22,7 @@ export const MAIL_SECURE = process.env.MAIL_SECURE ?? "false"; export const CLUB_NAME = process.env.CLUB_NAME ?? ""; export function configCheck() { + if (DB_TYPE == "" ?? typeof DB_TYPE != "string") throw new Error("set valid value to DB_TYPE"); if (DB_HOST == "" ?? typeof DB_HOST != "string") throw new Error("set valid value to DB_HOST"); if (DB_NAME == "" ?? typeof DB_NAME != "string") throw new Error("set valid value to DB_NAME"); if (DB_USERNAME == "" ?? typeof DB_USERNAME != "string") throw new Error("set valid value to DB_USERNAME");