mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Merged type fixes
This commit is contained in:
commit
6da7c5ec39
43 changed files with 4406 additions and 8284 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue