mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
init
This commit is contained in:
33
packages/server/src/database/database.ts
Normal file
33
packages/server/src/database/database.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import knex, { Knex } from 'knex';
|
||||
|
||||
import { source } from './migrations/migrations.source.js';
|
||||
|
||||
const tableNames = {
|
||||
loads: 'loads',
|
||||
};
|
||||
|
||||
class Database {
|
||||
#instance: Promise<Knex>;
|
||||
|
||||
constructor(config: Knex.Config) {
|
||||
this.#instance = this.#setup({
|
||||
...config,
|
||||
migrations: {
|
||||
migrationSource: source,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
#setup = async (config: Knex.Config) => {
|
||||
const db = knex(config);
|
||||
await db.migrate.latest();
|
||||
process.on('SIGINT', () => db.destroy());
|
||||
return db;
|
||||
};
|
||||
|
||||
public get instance() {
|
||||
return this.#instance;
|
||||
}
|
||||
}
|
||||
|
||||
export { Database, tableNames };
|
||||
Reference in New Issue
Block a user