Configuration
TSCord supports different databases:
- SQLite (by default)
- MySQL
- MariaDB
- PostgreSQL
By default, the template is configured to use SQLite. If your bot doesn't aim to be used on thousands of guilds with hundred of thousands of users, you should keep it.
Plus, SQLite is the only database supported by the automatic backup system.
You can configure all of this in the src/config/database.ts
file.
Indeed, this file exports a databaseType
and a mikroOrmConfig
constant, which contains a production configuration and an optional development configuration. At runtime, the good configuration is chosen thanks to the NODE_ENV environment variable.
The database type should be explicitely set in the databaseType
constant as it will be used to determine which entity manager type Mikro-ORM should use internaly.
You can find here the configuration for the different types of databases:
- SQLite
- PostgreSQL
- MySQL
- MariaDB
export const databaseType = 'better-sqlite' as const // (or 'sqlite')
{
type: databaseType,
dbName: `${databaseConfig.path}db.sqlite`, // path to the db .sqlite file
}
export const databaseType = 'postgresql' as const
{
type: databaseType,
dbName: process.env['DATABASE_NAME'],
host: process.env['DATABASE_HOST'],
port: 5432,
user: process.env['DATABASE_USER'],
password: process.env['DATABASE_PASSWORD'],
}
export const databaseType = 'mysql' as const
{
type: 'mysql',
dbName: process.env['DATABASE_NAME'],
host: process.env['DATABASE_HOST'],
port: 3306,
user: process.env['DATABASE_USER'],
password: process.env['DATABASE_PASSWORD'],
}
export const databaseType = 'mariadb' as const
{
type: 'mariadb',
dbName: process.env['DATABASE_NAME'],
host: process.env['DATABASE_HOST'],
port: 3306,
user: process.env['DATABASE_USER'],
password: process.env['DATABASE_PASSWORD'],
}
Env
You surely noticed that the database connection informations are stored in the environment variables.
You can edit it in the .env
file.
Example:
#...
DATABASE_HOST="database"
DATABASE_PORT=3306
DATABASE_NAME="tscord_bot"
DATABASE_USER="tscord"
DATABASE_PASSWORD="tscord123"
#...