Browse Source

Add initial integration with typeorm

ghorsington 5 years ago
parent
commit
36a1b7e720
6 changed files with 97 additions and 53 deletions
  1. 0 1
      .vscode/launch.json
  2. BIN
      database.sqlite
  3. 20 0
      ormconfig.json
  4. 54 51
      package.json
  5. 18 0
      src/entity/User.ts
  6. 5 1
      src/main.ts

+ 0 - 1
.vscode/launch.json

@@ -13,7 +13,6 @@
             "outFiles": [
                 "${workspaceFolder}/build/**/*.js"
             ],
-            "cwd": "${workspaceFolder}/build",
             "env": {
                 "NODE_ENV": "dev"
             }

BIN
database.sqlite


+ 20 - 0
ormconfig.json

@@ -0,0 +1,20 @@
+{
+   "type": "sqlite",
+   "database": "database.sqlite",
+   "synchronize": true,
+   "logging": false,
+   "entities": [
+      "build/entity/**/*.js"
+   ],
+   "migrations": [
+      "build/migration/**/*.js"
+   ],
+   "subscribers": [
+      "build/subscriber/**/*.js"
+   ],
+   "cli": {
+      "entitiesDir": "src/entity",
+      "migrationsDir": "src/migration",
+      "subscribersDir": "src/subscriber"
+   }
+}

+ 54 - 51
package.json

@@ -1,52 +1,55 @@
 {
-  "name": "noctbot",
-  "version": "1.0.0",
-  "description": "He is a Robot, his name is Noct. He is the Robo-Noct!",
-  "main": "main.js",
-  "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1",
-    "build": "tsc",
-    "start": "npm run build && node build/main.js"
-  },
-  "repository": {
-    "type": "git",
-    "url": "https://git.coder.horse/ghorsington/noctbot"
-  },
-  "keywords": [
-    "bot",
-    "noct",
-    "discord.js",
-    "discord"
-  ],
-  "author": "Geoffrey Horsington <geoffrey.hoooooorse@gmail.com>",
-  "license": "MIT",
-  "dependencies": {
-    "@types/dotenv": "^6.1.1",
-    "@types/lowdb": "^1.0.9",
-    "@types/request-promise-native": "^1.0.16",
-    "@types/sha1": "^1.1.2",
-    "@types/turndown": "^5.0.0",
-    "axios": "^0.19.0",
-    "discord.js": "^11.4.2",
-    "dotenv": "^8.0.0",
-    "interval-promise": "^1.2.0",
-    "jimp": "^0.5.4",
-    "lowdb": "^1.0.0",
-    "node-html-parser": "^1.1.16",
-    "opencv4nodejs": "^4.9.0",
-    "reflect-metadata": "^0.1.13",
-    "request": "^2.88.0",
-    "request-promise-native": "^1.0.5",
-    "rss-parser": "^3.4.3",
-    "sha1": "^1.1.1",
-    "sqlite3": "^4.0.9",
-    "translate-google": "^1.3.5",
-    "turndown": "^5.0.1",
-    "typeorm": "^0.2.18",
-    "typescript": "^3.5.2",
-    "uws": "^99.0.0"
-  },
-  "devDependencies": {
-    "eslint": "^5.16.0"
-  }
-}
+   "name": "noctbot",
+   "version": "1.0.0",
+   "description": "He is a Robot, his name is Noct. He is the Robo-Noct!",
+   "main": "main.js",
+   "scripts": {
+      "test": "echo \"Error: no test specified\" && exit 1",
+      "build": "tsc",
+      "start": "ts-node src/index.ts"
+   },
+   "repository": {
+      "type": "git",
+      "url": "https://git.coder.horse/ghorsington/noctbot"
+   },
+   "keywords": [
+      "bot",
+      "noct",
+      "discord.js",
+      "discord"
+   ],
+   "author": "Geoffrey Horsington <geoffrey.hoooooorse@gmail.com>",
+   "license": "MIT",
+   "dependencies": {
+      "@types/dotenv": "^6.1.1",
+      "@types/lowdb": "^1.0.9",
+      "@types/request-promise-native": "^1.0.16",
+      "@types/sha1": "^1.1.2",
+      "@types/turndown": "^5.0.0",
+      "axios": "^0.19.0",
+      "discord.js": "^11.4.2",
+      "dotenv": "^8.0.0",
+      "interval-promise": "^1.2.0",
+      "jimp": "^0.5.4",
+      "lowdb": "^1.0.0",
+      "node-html-parser": "^1.1.16",
+      "opencv4nodejs": "^4.9.0",
+      "reflect-metadata": "^0.1.10",
+      "request": "^2.88.0",
+      "request-promise-native": "^1.0.5",
+      "rss-parser": "^3.4.3",
+      "sha1": "^1.1.1",
+      "sqlite3": "^4.0.3",
+      "translate-google": "^1.3.5",
+      "turndown": "^5.0.1",
+      "typeorm": "0.2.18",
+      "typescript": "^3.5.2",
+      "uws": "^99.0.0"
+   },
+   "devDependencies": {
+      "eslint": "^5.16.0",
+      "ts-node": "3.3.0",
+      "@types/node": "^8.0.29",
+      "typescript": "3.3.3333"
+   }
+}

+ 18 - 0
src/entity/User.ts

@@ -0,0 +1,18 @@
+import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
+
+@Entity()
+export class User {
+
+    @PrimaryGeneratedColumn()
+    id: number;
+
+    @Column()
+    firstName: string;
+
+    @Column()
+    lastName: string;
+
+    @Column()
+    age: number;
+
+}

+ 5 - 1
src/main.ts

@@ -4,6 +4,8 @@ import * as path from "path";
 import client from "./client";
 import { shouldShowMaintenanceMessage, documentation } from "./util";
 import { ICommand, BotEvent, IBotCommand } from "./commands/command"
+import "reflect-metadata";
+import {createConnection} from "typeorm";
 
 dotenv.config();
 const REACT_PROBABILITY = 0.3;
@@ -89,7 +91,9 @@ client.on("messageReactionAdd", (r, u) => {
     }
 });
 
-function main() {
+async function main() {
+    await createConnection();
+
     let commandsPath = path.resolve(path.dirname(module.filename), "commands");
     let files = fs.readdirSync(commandsPath);