Merged type fixes

This commit is contained in:
mrfry 2022-03-20 13:06:25 +01:00
commit 6da7c5ec39
43 changed files with 4406 additions and 8284 deletions

View file

@ -16,7 +16,7 @@ export default {
sanitizeQuery: sanitizeQuery,
}
import Sqlite from 'better-sqlite3'
import Sqlite, { Database } from 'better-sqlite3'
import logger from '../utils/logger'
import utils from '../utils/utils'
@ -60,7 +60,7 @@ function GetDB(path: string): any {
return res
}
function DebugLog(msg) {
function DebugLog(msg: string) {
if (debugLog) {
logger.DebugLog(msg, 'sql', 0)
}
@ -139,7 +139,7 @@ function CreateTable(db: any, name: any, columns: any, foreignKeys: any): any {
const cols = Object.keys(columns)
.reduce((acc, key) => {
const item = columns[key]
const flags = []
const flags: string[] = []
const toCheck = {
primary: 'PRIMARY KEY',
notNull: 'NOT NULL',
@ -158,16 +158,22 @@ function CreateTable(db: any, name: any, columns: any, foreignKeys: any): any {
}, [])
.join(', ')
const fKeys = []
const fKeys: string[] = []
if (foreignKeys) {
foreignKeys.forEach((foreignKey) => {
const { keysFrom, table, keysTo } = foreignKey
fKeys.push(
`, FOREIGN KEY(${keysFrom.join(
', '
)}) REFERENCES ${table}(${keysTo.join(', ')})`
)
})
foreignKeys.forEach(
(foreignKey: {
keysFrom: string[]
table: string
keysTo: string[]
}) => {
const { keysFrom, table, keysTo } = foreignKey
fKeys.push(
`, FOREIGN KEY(${keysFrom.join(
', '
)}) REFERENCES ${table}(${keysTo.join(', ')})`
)
}
)
}
// IF NOT EXISTS
@ -252,7 +258,7 @@ function runStatement(db: any, command: string, runType?: string): any {
}
function CloseDB(db: any): void {
db.close((err) => {
db.close((err: Error) => {
if (err) {
return console.error(err.message)
}
@ -262,7 +268,7 @@ function CloseDB(db: any): void {
// -------------------------------------------------------------------------
function PrepareStatement(db, command) {
function PrepareStatement(db: Database, command: string) {
if (!db) {
throw new Error(
'DB is undefined in prepare statement! DB action called with undefined db'