mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-22 02:12:40 +01:00
feat: better-sqlite3 support
This commit is contained in:
parent
d086c053bb
commit
197f1aacd2
@ -112,6 +112,7 @@
|
||||
"@fosscord/util": "dist/util"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"better-sqlite3": "^8.2.0",
|
||||
"erlpack": "^0.1.4",
|
||||
"nodemailer-mailgun-transport": "^2.1.5",
|
||||
"nodemailer-mailjet-transport": "github:n0script22/nodemailer-mailjet-transport",
|
||||
|
@ -36,9 +36,17 @@ if (!process.env) {
|
||||
const dbConnectionString =
|
||||
process.env.DATABASE || path.join(process.cwd(), "database.db");
|
||||
|
||||
const DatabaseType = dbConnectionString.includes("://")
|
||||
let DatabaseType = dbConnectionString.includes("://")
|
||||
? dbConnectionString.split(":")[0]?.replace("+srv", "")
|
||||
: "sqlite";
|
||||
|
||||
if (DatabaseType === "sqlite") {
|
||||
try {
|
||||
require("better-sqlite3");
|
||||
DatabaseType = "better-sqlite3";
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (error) {}
|
||||
}
|
||||
const isSqlite = DatabaseType.includes("sqlite");
|
||||
|
||||
const DataSourceOptions = new DataSource({
|
||||
@ -55,6 +63,7 @@ const DataSourceOptions = new DataSource({
|
||||
supportBigNumbers: true,
|
||||
name: "default",
|
||||
migrations: [path.join(__dirname, "..", "migration", DatabaseType, "*.js")],
|
||||
cache: true,
|
||||
});
|
||||
|
||||
// Gets the existing database connection
|
||||
@ -77,7 +86,13 @@ export async function initDatabase(): Promise<DataSource> {
|
||||
}
|
||||
|
||||
if (!process.env.DB_SYNC) {
|
||||
const supported = ["mysql", "mariadb", "postgres", "sqlite"];
|
||||
const supported = [
|
||||
"mysql",
|
||||
"mariadb",
|
||||
"postgres",
|
||||
"sqlite",
|
||||
"better-sqlite3",
|
||||
];
|
||||
if (!supported.includes(DatabaseType)) {
|
||||
console.log(
|
||||
"[Database]" +
|
||||
|
Loading…
Reference in New Issue
Block a user