mirror of
https://github.com/thedrewen/protojx-manager.git
synced 2026-03-23 05:01:54 +01:00
feat(database): add TypeORM configuration and initialize data source
- Added TypeORM and PostgreSQL dependencies to package.json. - Created data-source.ts to configure the database connection. - Initialized the data source in index.ts and added logging for successful connection. - Updated devDependencies to include @types/node for better type support.
This commit is contained in:
17
.env.example
17
.env.example
@@ -1,5 +1,18 @@
|
||||
TOKEN=
|
||||
CLIENT_ID=
|
||||
# Discord Bot Configuration
|
||||
TOKEN=your_discord_bot_token_here
|
||||
CLIENT_ID=your_discord_client_id_here
|
||||
|
||||
# Custom Emojis
|
||||
EMOJI_STATUS_ONLINE=<a:online:1432684754276323431>
|
||||
EMOJI_STATUS_OFFLINE=<a:offline:1432684900175183882>
|
||||
|
||||
# Database Configuration
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_USERNAME=postgres
|
||||
DB_PASSWORD=your_database_password_here
|
||||
DB_DATABASE=protojx_manager
|
||||
DB_LOGGING=false
|
||||
|
||||
# Environment
|
||||
NODE_ENV=development
|
||||
1511
package-lock.json
generated
1511
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/Under-scape/discordbot-ts-template#readme",
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.9.2",
|
||||
"typescript": "^5.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -31,6 +32,9 @@
|
||||
"cron": "^4.3.3",
|
||||
"discord.js": "^14.24.1",
|
||||
"dotenv": "^17.2.2",
|
||||
"ping": "^1.0.0"
|
||||
"pg": "^8.16.3",
|
||||
"ping": "^1.0.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"typeorm": "^0.3.27"
|
||||
}
|
||||
}
|
||||
|
||||
19
src/data-source.ts
Normal file
19
src/data-source.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource } from "typeorm"
|
||||
import { configDotenv } from "dotenv"
|
||||
|
||||
configDotenv()
|
||||
|
||||
export const AppDataSource = new DataSource({
|
||||
type: "postgres",
|
||||
host: process.env.DB_HOST || "localhost",
|
||||
port: parseInt(process.env.DB_PORT || "5432"),
|
||||
username: process.env.DB_USERNAME || "postgres",
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_DATABASE,
|
||||
synchronize: process.env.NODE_ENV !== "production", // false en production
|
||||
logging: process.env.DB_LOGGING === "true",
|
||||
entities: ["./entity/**/*.js"],
|
||||
migrations: ["./migration/**/*.js"],
|
||||
subscribers: ["./subscriber/**/*.js"],
|
||||
})
|
||||
@@ -4,8 +4,17 @@ import path from "path";
|
||||
import fs from "fs";
|
||||
import statusService from "./services/status.service";
|
||||
|
||||
import "reflect-metadata";
|
||||
import { AppDataSource } from "./data-source";
|
||||
|
||||
configDotenv();
|
||||
|
||||
AppDataSource.initialize()
|
||||
.then(() => {
|
||||
console.log("Data Source initialized !")
|
||||
})
|
||||
.catch((error) => console.log(error));
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
|
||||
Reference in New Issue
Block a user