Merge branch 'main' into new-admin
This commit is contained in:
commit
8a5c8c332c
5 changed files with 57 additions and 53 deletions
|
@ -1,4 +1,4 @@
|
|||
import {RunResult, SqlType, Statement, TypedDatabase} from "../database";
|
||||
import {RunResult, SqlType, Statement, TypedDatabase} from "../../types";
|
||||
import * as sqlite3 from "sqlite3";
|
||||
|
||||
export async function init(): Promise<void> {
|
||||
|
|
|
@ -4,60 +4,13 @@ import glob from "glob";
|
|||
import path from "path";
|
||||
import {config} from "../config";
|
||||
import Logger from "../logger";
|
||||
import {Database, ISqlite, open, Statement} from "sqlite";
|
||||
import {Database, open, Statement} from "sqlite";
|
||||
import * as sqlite3 from "sqlite3";
|
||||
import {RunResult, SqlType, TypedDatabase} from "../types";
|
||||
|
||||
const pglob = util.promisify(glob);
|
||||
const pReadFile = util.promisify(fs.readFile);
|
||||
|
||||
export type RunResult = ISqlite.RunResult;
|
||||
export type SqlType = ISqlite.SqlType;
|
||||
|
||||
export interface TypedDatabase {
|
||||
/**
|
||||
* @see Database.on
|
||||
*/
|
||||
on(event: string, listener: any): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see Database.run
|
||||
*/
|
||||
run(sql: SqlType, ...params: any[]): Promise<RunResult>;
|
||||
|
||||
/**
|
||||
* @see Database.get
|
||||
*/
|
||||
get<T>(sql: SqlType, ...params: any[]): Promise<T | undefined>;
|
||||
|
||||
/**
|
||||
* @see Database.each
|
||||
*/
|
||||
each<T>(sql: SqlType, callback: (err: any, row: T) => void): Promise<number>;
|
||||
|
||||
each<T>(sql: SqlType, param1: any, callback: (err: any, row: T) => void): Promise<number>;
|
||||
|
||||
each<T>(sql: SqlType, param1: any, param2: any, callback: (err: any, row: T) => void): Promise<number>;
|
||||
|
||||
each<T>(sql: SqlType, param1: any, param2: any, param3: any, callback: (err: any, row: T) => void): Promise<number>;
|
||||
|
||||
each<T>(sql: SqlType, ...params: any[]): Promise<number>;
|
||||
|
||||
/**
|
||||
* @see Database.all
|
||||
*/
|
||||
all<T = never>(sql: SqlType, ...params: any[]): Promise<T[]>;
|
||||
|
||||
/**
|
||||
* @see Database.exec
|
||||
*/
|
||||
exec(sql: SqlType, ...params: any[]): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see Database.prepare
|
||||
*/
|
||||
prepare(sql: SqlType, ...params: any[]): Promise<Statement>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Typesafe database wrapper.
|
||||
*
|
||||
|
@ -174,5 +127,3 @@ export async function init(): Promise<void> {
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export {Statement};
|
||||
|
|
|
@ -3,7 +3,7 @@ import moment, {Moment, unitOfTime} from "moment";
|
|||
import request from "request";
|
||||
|
||||
import {config} from "../config";
|
||||
import {db, RunResult} from "../db/database";
|
||||
import {db} from "../db/database";
|
||||
import * as DatabaseUtil from "../utils/databaseUtil";
|
||||
import ErrorTypes from "../utils/errorTypes";
|
||||
import Logger from "../logger";
|
||||
|
@ -29,6 +29,7 @@ import {
|
|||
NodeId,
|
||||
NodeStateData,
|
||||
OnlineState,
|
||||
RunResult,
|
||||
Site,
|
||||
UnixTimestampSeconds
|
||||
} from "../types";
|
||||
|
|
51
server/types/database.ts
Normal file
51
server/types/database.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import {ISqlite, Statement} from "sqlite";
|
||||
|
||||
export type RunResult = ISqlite.RunResult;
|
||||
export type SqlType = ISqlite.SqlType;
|
||||
|
||||
export {Statement};
|
||||
|
||||
export interface TypedDatabase {
|
||||
/**
|
||||
* @see Database.on
|
||||
*/
|
||||
on(event: string, listener: any): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see Database.run
|
||||
*/
|
||||
run(sql: SqlType, ...params: any[]): Promise<RunResult>;
|
||||
|
||||
/**
|
||||
* @see Database.get
|
||||
*/
|
||||
get<T>(sql: SqlType, ...params: any[]): Promise<T | undefined>;
|
||||
|
||||
/**
|
||||
* @see Database.each
|
||||
*/
|
||||
each<T>(sql: SqlType, callback: (err: any, row: T) => void): Promise<number>;
|
||||
|
||||
each<T>(sql: SqlType, param1: any, callback: (err: any, row: T) => void): Promise<number>;
|
||||
|
||||
each<T>(sql: SqlType, param1: any, param2: any, callback: (err: any, row: T) => void): Promise<number>;
|
||||
|
||||
each<T>(sql: SqlType, param1: any, param2: any, param3: any, callback: (err: any, row: T) => void): Promise<number>;
|
||||
|
||||
each<T>(sql: SqlType, ...params: any[]): Promise<number>;
|
||||
|
||||
/**
|
||||
* @see Database.all
|
||||
*/
|
||||
all<T = never>(sql: SqlType, ...params: any[]): Promise<T[]>;
|
||||
|
||||
/**
|
||||
* @see Database.exec
|
||||
*/
|
||||
exec(sql: SqlType, ...params: any[]): Promise<void>;
|
||||
|
||||
/**
|
||||
* @see Database.prepare
|
||||
*/
|
||||
prepare(sql: SqlType, ...params: any[]): Promise<Statement>;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import {Domain, EmailAddress, JSONObject, MonitoringToken, OnlineState, Site, toIsEnum} from "./shared";
|
||||
|
||||
export * from "./config";
|
||||
export * from "./database";
|
||||
export * from "./logger";
|
||||
export * from "./shared";
|
||||
|
||||
|
|
Loading…
Reference in a new issue