Fixing mismatching database paths
This commit is contained in:
parent
3bef2a8819
commit
f84928a35b
1 changed files with 4 additions and 2 deletions
|
|
@ -3,8 +3,10 @@ import sqlite from 'sqlite3'
|
||||||
import { asyncLocalStorage } from '../logger'
|
import { asyncLocalStorage } from '../logger'
|
||||||
import { CREATE_TABLE_reservations } from './sql'
|
import { CREATE_TABLE_reservations } from './sql'
|
||||||
|
|
||||||
|
const getDatabase = () => new sqlite.Database(resolve('./db/autobaan_db'))
|
||||||
|
|
||||||
export const run = async (sql: string, params?: unknown) => {
|
export const run = async (sql: string, params?: unknown) => {
|
||||||
const db = new sqlite.Database(resolve('./db/autobaan_db'))
|
const db = getDatabase()
|
||||||
await new Promise<void>((res, rej) => {
|
await new Promise<void>((res, rej) => {
|
||||||
asyncLocalStorage.getStore()?.debug(`<database> run ${sql} (${params})`)
|
asyncLocalStorage.getStore()?.debug(`<database> run ${sql} (${params})`)
|
||||||
db.run(sql, params, (err) => {
|
db.run(sql, params, (err) => {
|
||||||
|
|
@ -16,7 +18,7 @@ export const run = async (sql: string, params?: unknown) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const all = async <T>(sql: string, params?: unknown) => {
|
export const all = async <T>(sql: string, params?: unknown) => {
|
||||||
const db = new sqlite.Database(resolve('autobaan_db'))
|
const db = getDatabase()
|
||||||
const rows = await new Promise<T[]>((res, rej) => {
|
const rows = await new Promise<T[]>((res, rej) => {
|
||||||
asyncLocalStorage.getStore()?.debug(`<database> all ${sql} (${params})`)
|
asyncLocalStorage.getStore()?.debug(`<database> all ${sql} (${params})`)
|
||||||
db.all(sql, params, (err, rows) => {
|
db.all(sql, params, (err, rows) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue