This commit is contained in:
Morten Olsen
2024-01-11 09:03:14 +01:00
commit 36f63662ad
82 changed files with 7071 additions and 0 deletions

View 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 };