move sql to it own file
This commit is contained in:
parent
1b11a3728f
commit
a5bddd8c6f
3 changed files with 30 additions and 23 deletions
13
src/sql/init.sql
Normal file
13
src/sql/init.sql
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS
|
||||||
|
reminder (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
data TEXT,
|
||||||
|
expiration_date TEXT,
|
||||||
|
option_id INTEGER,
|
||||||
|
channel_id TEXT,
|
||||||
|
creation_date TEXT,
|
||||||
|
user_id TEXT,
|
||||||
|
guild_id TEXT,
|
||||||
|
locale TEXT,
|
||||||
|
timeout_id TEXT
|
||||||
|
);
|
|
@ -5,6 +5,7 @@ import { Database } from "sqlite3";
|
||||||
import "../modules/client";
|
import "../modules/client";
|
||||||
import { loadLocales } from "./locales";
|
import { loadLocales } from "./locales";
|
||||||
import { YoutubeiExtractor } from "discord-player-youtubei";
|
import { YoutubeiExtractor } from "discord-player-youtubei";
|
||||||
|
import { readSQL } from "./db";
|
||||||
|
|
||||||
/** Creation of the client and definition of its properties */
|
/** Creation of the client and definition of its properties */
|
||||||
export default async (isDev: boolean) => {
|
export default async (isDev: boolean) => {
|
||||||
|
@ -59,7 +60,7 @@ export default async (isDev: boolean) => {
|
||||||
|
|
||||||
client.db = new Database(`${process.env.DOCKERIZED === "1" ? "/config" : "./config"}/db.sqlite3`);
|
client.db = new Database(`${process.env.DOCKERIZED === "1" ? "/config" : "./config"}/db.sqlite3`);
|
||||||
|
|
||||||
initDatabase(client.db);
|
client.db.run(readSQL("init"));
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
};
|
};
|
||||||
|
@ -75,25 +76,3 @@ export const quit = (client: Client) => {
|
||||||
// Close client
|
// Close client
|
||||||
client.destroy();
|
client.destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Initalize the database
|
|
||||||
* @param db Database
|
|
||||||
*/
|
|
||||||
const initDatabase = (db: Database) => {
|
|
||||||
// Table for reminders
|
|
||||||
db.run(
|
|
||||||
"CREATE TABLE IF NOT EXISTS reminder ( \
|
|
||||||
id INTEGER PRIMARY KEY, \
|
|
||||||
data TEXT, \
|
|
||||||
expiration_date TEXT, \
|
|
||||||
option_id INTEGER, \
|
|
||||||
channel_id TEXT, \
|
|
||||||
creation_date TEXT, \
|
|
||||||
user_id TEXT, \
|
|
||||||
guild_id TEXT, \
|
|
||||||
locale TEXT, \
|
|
||||||
timeout_id TEXT \
|
|
||||||
);",
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
15
src/utils/db.ts
Normal file
15
src/utils/db.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import fs from "node:fs";
|
||||||
|
|
||||||
|
export const readSQL = (path: string) => {
|
||||||
|
const dir = "./src/sql/";
|
||||||
|
if (!path.startsWith(dir)) {
|
||||||
|
path = dir + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ext = ".sql";
|
||||||
|
if (!path.endsWith(ext)) {
|
||||||
|
path += ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fs.readFileSync(path, "utf8");
|
||||||
|
};
|
Loading…
Reference in a new issue