Revert "partial conversion to typeORM, error on init tho"
This reverts commit d2371cbd52
.
This commit is contained in:
parent
d2371cbd52
commit
a57f399314
11 changed files with 55 additions and 2211 deletions
3
.env
3
.env
|
@ -1,3 +0,0 @@
|
||||||
WEBHOOK_URL=https://discord.com/api/webhooks/1322002321957191710/M0OBUFRzZhnkkmOOyBw-bx07sGSUae5kvfQN4gGNrgMp_KkTF__4ZLANF5SbT0y8ASap
|
|
||||||
WEBHOOK_NAME=Auction_Notifier
|
|
||||||
WEBHOOK_PROFILE_PICTURE=https://www.speedrun.com/static/game/3dxe951y/cover.png?v=14e2c50
|
|
13
.gitignore
vendored
13
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
||||||
.idea/
|
node_modules
|
||||||
.vscode/
|
.env
|
||||||
node_modules/
|
pnpm-lock*
|
||||||
build/
|
dist
|
||||||
tmp/
|
*.db
|
||||||
temp/
|
*.sqlite*
|
||||||
|
db_data
|
1
index.ts
1
index.ts
|
@ -6,7 +6,6 @@ import { string } from 'prismarine-nbt';
|
||||||
import { SqlSystem } from './src/sqlFunctions';
|
import { SqlSystem } from './src/sqlFunctions';
|
||||||
import { setupErrorHandlers } from './src/errorHandler';
|
import { setupErrorHandlers } from './src/errorHandler';
|
||||||
import { ItemCompactData } from './src/Types';
|
import { ItemCompactData } from './src/Types';
|
||||||
import "reflect-metadata"
|
|
||||||
|
|
||||||
setupErrorHandlers();
|
setupErrorHandlers();
|
||||||
|
|
||||||
|
|
18
package.json
18
package.json
|
@ -7,31 +7,23 @@
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "ts-node src/index.ts",
|
"start": "node dist/index.js",
|
||||||
"dev": "ts-node index.ts",
|
"dev": "ts-node index.ts"
|
||||||
"typeorm": "typeorm-ts-node-commonjs"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/node": "^22.10.2",
|
||||||
"@types/toastify-js": "^1.12.3",
|
"@types/toastify-js": "^1.12.3",
|
||||||
"axios": "^0.24.0",
|
"axios": "^0.24.0",
|
||||||
"copy-paste": "^1.5.3",
|
"copy-paste": "^1.5.3",
|
||||||
"discord.js": "^14.16.3",
|
"discord.js": "^14.16.3",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"mysql2": "^3.12.0",
|
"mariadb": "^3.4.0",
|
||||||
"node-notifier": "^10.0.1",
|
"node-notifier": "^10.0.1",
|
||||||
"open": "^8.4.2",
|
"open": "^8.4.2",
|
||||||
"prismarine-nbt": "^2.7.0",
|
"prismarine-nbt": "^2.7.0",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"toastify-js": "^1.12.0",
|
"toastify-js": "^1.12.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typeorm": "0.3.20",
|
"typescript": "^5.7.2"
|
||||||
"typescript": "^5.7.2",
|
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"mysql": "^2.14.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "^16.11.10",
|
|
||||||
"ts-node": "10.9.1",
|
|
||||||
"typescript": "4.5.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
1981
pnpm-lock.yaml
1981
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
|
@ -1,17 +0,0 @@
|
||||||
import "reflect-metadata"
|
|
||||||
import { DataSource } from "typeorm"
|
|
||||||
import { User } from "./entity/User"
|
|
||||||
|
|
||||||
export const AppDataSource = new DataSource({
|
|
||||||
type: "mariadb",
|
|
||||||
host: "localhost",
|
|
||||||
port: 3306,
|
|
||||||
username: "test",
|
|
||||||
password: "test",
|
|
||||||
database: "test",
|
|
||||||
synchronize: true,
|
|
||||||
logging: false,
|
|
||||||
entities: [User],
|
|
||||||
migrations: [],
|
|
||||||
subscribers: [],
|
|
||||||
})
|
|
|
@ -1,18 +0,0 @@
|
||||||
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"
|
|
||||||
|
|
||||||
@Entity()
|
|
||||||
export class User {
|
|
||||||
|
|
||||||
@PrimaryGeneratedColumn()
|
|
||||||
id: number
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
firstName: string
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
lastName: string
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
age: number
|
|
||||||
|
|
||||||
}
|
|
20
src/index.ts
20
src/index.ts
|
@ -1,20 +0,0 @@
|
||||||
import { AppDataSource } from "./data-source"
|
|
||||||
import { User } from "./entity/User"
|
|
||||||
|
|
||||||
AppDataSource.initialize().then(async () => {
|
|
||||||
|
|
||||||
console.log("Inserting a new user into the database...")
|
|
||||||
const user = new User()
|
|
||||||
user.firstName = "Timber"
|
|
||||||
user.lastName = "Saw"
|
|
||||||
user.age = 25
|
|
||||||
await AppDataSource.manager.save(user)
|
|
||||||
console.log("Saved a new user with id: " + user.id)
|
|
||||||
|
|
||||||
console.log("Loading users from the database...")
|
|
||||||
const users = await AppDataSource.manager.find(User)
|
|
||||||
console.log("Loaded users: ", users)
|
|
||||||
|
|
||||||
console.log("Here you can setup and run express / fastify / any other framework.")
|
|
||||||
|
|
||||||
}).catch(error => console.log(error))
|
|
|
@ -1,81 +0,0 @@
|
||||||
// migrations/CreateDbExtras.ts
|
|
||||||
|
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class CreateDbExtras implements MigrationInterface {
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
// Triggers
|
|
||||||
await queryRunner.query(`
|
|
||||||
DELIMITER $$
|
|
||||||
|
|
||||||
-- Insert
|
|
||||||
CREATE TRIGGER IF NOT EXISTS insertLifetime
|
|
||||||
AFTER INSERT ON auctions
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
INSERT INTO lifetimes (id, insertedon) VALUES (NEW.id, NOW(2));
|
|
||||||
END$$
|
|
||||||
|
|
||||||
-- Update
|
|
||||||
CREATE TRIGGER IF NOT EXISTS updateLifetime
|
|
||||||
AFTER UPDATE ON auctions
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
UPDATE lifetimes SET insertedon = NOW(2) WHERE id = NEW.id;
|
|
||||||
END$$
|
|
||||||
|
|
||||||
-- Delete
|
|
||||||
CREATE TRIGGER IF NOT EXISTS removeLifetime
|
|
||||||
BEFORE DELETE ON auctions
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
DELETE FROM lifetimes WHERE id = OLD.id;
|
|
||||||
END$$
|
|
||||||
|
|
||||||
DELIMITER ;
|
|
||||||
`);
|
|
||||||
|
|
||||||
// Stored procedure + event
|
|
||||||
await queryRunner.query(`
|
|
||||||
DELIMITER $$
|
|
||||||
CREATE PROCEDURE IF NOT EXISTS CleanupOldEntries()
|
|
||||||
BEGIN
|
|
||||||
DECLARE done INT DEFAULT 0;
|
|
||||||
DECLARE temp_id INT;
|
|
||||||
|
|
||||||
DECLARE cur CURSOR FOR
|
|
||||||
SELECT id
|
|
||||||
FROM lifetimes
|
|
||||||
WHERE TIMESTAMPDIFF(HOUR, insertedon, NOW()) >= 6;
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
|
|
||||||
|
|
||||||
OPEN cur;
|
|
||||||
read_loop: LOOP
|
|
||||||
FETCH cur INTO temp_id;
|
|
||||||
IF done THEN
|
|
||||||
LEAVE read_loop;
|
|
||||||
END IF;
|
|
||||||
DELETE FROM auctions WHERE id = temp_id;
|
|
||||||
END LOOP;
|
|
||||||
CLOSE cur;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
||||||
|
|
||||||
SET GLOBAL event_scheduler = ON;
|
|
||||||
|
|
||||||
CREATE EVENT IF NOT EXISTS CleanupOldEntriesEvent
|
|
||||||
ON SCHEDULE EVERY 2 MINUTE
|
|
||||||
DO
|
|
||||||
CALL CleanupOldEntries();
|
|
||||||
`);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
// Reverse: drop triggers, event, procedure, etc.
|
|
||||||
await queryRunner.query(`DROP EVENT IF EXISTS CleanupOldEntriesEvent;`);
|
|
||||||
await queryRunner.query(`DROP PROCEDURE IF EXISTS CleanupOldEntries;`);
|
|
||||||
await queryRunner.query(`DROP TRIGGER IF EXISTS removeLifetime;`);
|
|
||||||
await queryRunner.query(`DROP TRIGGER IF EXISTS updateLifetime;`);
|
|
||||||
await queryRunner.query(`DROP TRIGGER IF EXISTS insertLifetime;`);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +1,10 @@
|
||||||
import { DataSource, Entity, PrimaryGeneratedColumn, Column, PrimaryColumn } from "typeorm";
|
import mariadb from 'mariadb';
|
||||||
import { loadConfig } from './configLoader';
|
import { loadConfig } from './configLoader';
|
||||||
import { CreateDbExtras } from "./migration/CreateDBExtras";
|
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
|
|
||||||
|
|
||||||
@Entity()
|
|
||||||
class Auction {
|
|
||||||
@PrimaryGeneratedColumn()
|
|
||||||
id: number;
|
|
||||||
|
|
||||||
@Column("varchar", { length: 255, unique: true })
|
|
||||||
auctionid: string;
|
|
||||||
|
|
||||||
@Column("decimal", { precision: 65, scale: 5 })
|
|
||||||
lbin: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity()
|
|
||||||
export class Lifetime {
|
|
||||||
@PrimaryColumn()
|
|
||||||
id: number;
|
|
||||||
|
|
||||||
@Column('datetime', { precision: 2 })
|
|
||||||
insertedon: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
class SqlSystem {
|
class SqlSystem {
|
||||||
|
|
||||||
private static DS: DataSource = new DataSource({
|
private static pool: mariadb.Pool = mariadb.createPool({ database: process.env.DATABASE, host: process.env.DB_HOST, user: process.env.DB_USER, password: process.env.DB_PASSWORD, connectionLimit: config.data.worker_count ?? 10 })
|
||||||
type: "mariadb",
|
|
||||||
host: process.env.DB_HOST,
|
|
||||||
port: 3306,
|
|
||||||
username: process.env.DB_USER,
|
|
||||||
password: process.env.DB_PASSWORD,
|
|
||||||
database: "hypixel",
|
|
||||||
synchronize: true,
|
|
||||||
entities: [Auction, Lifetime],
|
|
||||||
migrations: [CreateDbExtras],
|
|
||||||
});
|
|
||||||
|
|
||||||
public static async InitDB() {
|
public static async InitDB() {
|
||||||
let conn: mariadb.PoolConnection | undefined;
|
let conn: mariadb.PoolConnection | undefined;
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": [
|
"module": "NodeNext",
|
||||||
"es5",
|
"moduleResolution": "nodenext",
|
||||||
"es6"
|
"target": "ES2024",
|
||||||
],
|
"jsx": "preserve",
|
||||||
"target": "es5",
|
"strictNullChecks": true,
|
||||||
"module": "commonjs",
|
"strictFunctionTypes": true,
|
||||||
"moduleResolution": "node",
|
"sourceMap": true,
|
||||||
"outDir": "./build",
|
"resolveJsonModule": true,
|
||||||
"emitDecoratorMetadata": true,
|
"esModuleInterop": true,
|
||||||
"experimentalDecorators": true,
|
"skipLibCheck": true,
|
||||||
"sourceMap": true
|
"outDir": "./dist",
|
||||||
}
|
"strict": true,
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"**/node_modules/*"
|
||||||
|
]
|
||||||
}
|
}
|
Loading…
Reference in a new issue