docs: completed v1 docs (#36)

This commit is contained in:
Morten Olsen
2024-01-15 15:10:19 +01:00
committed by GitHub
parent 161a098c9f
commit 1c3b993ab2
27 changed files with 226 additions and 41 deletions

View File

@@ -1,6 +1,8 @@
import knex, { Knex } from 'knex';
import { source } from './migrations/migrations.source.js';
import { mkdir } from 'fs/promises';
import { dirname } from 'path';
const tableNames = {
loads: 'loads',
@@ -20,6 +22,15 @@ class Database {
}
#setup = async (config: Knex.Config) => {
if (
config.connection &&
typeof config.connection !== 'string' &&
'filename' in config.connection &&
typeof config.connection.filename === 'string' &&
config.connection.filename !== ':memory:'
) {
await mkdir(dirname(config.connection.filename), { recursive: true });
}
const db = knex(config);
await db.migrate.latest();
return db;