/nergal

The backbone for discord bot project with a support of proper OOP, typescript, sqlite3, unit tests and migrations.

Primary LanguageTypeScript

Running tests

npm run test

Compilation

npm run compile

Project setup

Add following commands into the package.json scripts structure:

{
    "scripts": {
        "nergal": "node_modules/.bin/ts-node console.ts",
        "migrate": "node_modules/db-migrate/bin/db-migrate",
        "start": "node_modules/.bin/ts-node run.ts",
        "compile": "node_modules/typescript/bin/tsc --listEmittedFiles",
        "test": "node_modules/.bin/ts-node test/startup.ts && node_modules/.bin/mocha \"./test/*.test.ts\""
      },
}

Then init the project:

node node_modules/nergal/init

Migrations

To create new migration run

npm run migrate create <migration name>

Creating new table:

await db.createTable('votes', {
    id: { type: 'int', primaryKey: true, autoIncrement: true},
    participant_id: 'int',
    voter_discord_id: 'string',
  });

Adding indexes:

db.addIndex('votes', 'unique_voter_and_participant', ['participant_id', 'voter_discord_id'], true);

Dropping table

return db.dropTable('votes');

Adding column

await db.addColumn('votes', 'voter_discord_name', 'string');

Removing column

db.removeColumn('votes');

Running migrations

npm run migrate up

Running in dev mode

npm run start

Running console commands

npm run console