mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 20:17:02 +03:00
type IDatabase::prepare with overloads
This commit is contained in:
@@ -3,7 +3,6 @@ import { CronJob } from "cron";
|
|||||||
import { config as serverConfig } from "../config";
|
import { config as serverConfig } from "../config";
|
||||||
import { Logger } from "../utils/logger";
|
import { Logger } from "../utils/logger";
|
||||||
import { db } from "../databases/databases";
|
import { db } from "../databases/databases";
|
||||||
import { DBSegment } from "../types/segments.model";
|
|
||||||
|
|
||||||
const jobConfig = serverConfig?.crons?.downvoteSegmentArchive;
|
const jobConfig = serverConfig?.crons?.downvoteSegmentArchive;
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ export const archiveDownvoteSegment = async (dayLimit: number, voteLimit: number
|
|||||||
timeNow,
|
timeNow,
|
||||||
threshold
|
threshold
|
||||||
]
|
]
|
||||||
) as DBSegment[];
|
);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.error("Execption when insert segment in archivedSponsorTimes");
|
Logger.error("Execption when insert segment in archivedSponsorTimes");
|
||||||
@@ -43,7 +42,7 @@ export const archiveDownvoteSegment = async (dayLimit: number, voteLimit: number
|
|||||||
timeNow,
|
timeNow,
|
||||||
threshold
|
threshold
|
||||||
]
|
]
|
||||||
) as DBSegment[];
|
);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.error("Execption when deleting segment in sponsorTimes");
|
Logger.error("Execption when deleting segment in sponsorTimes");
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ export interface QueryOption {
|
|||||||
export interface IDatabase {
|
export interface IDatabase {
|
||||||
init(): Promise<void>;
|
init(): Promise<void>;
|
||||||
|
|
||||||
prepare(type: QueryType, query: string, params?: any[], options?: QueryOption): Promise<any | any[] | void>;
|
prepare(type: "run", query: string, params?: any[], options?: QueryOption): Promise<void>;
|
||||||
|
prepare(type: "get", query: string, params?: any[], options?: QueryOption): Promise<any>;
|
||||||
|
prepare(type: "all", query: string, params?: any[], options?: QueryOption): Promise<any[]>;
|
||||||
|
prepare(type: QueryType, query: string, params?: any[], options?: QueryOption): Promise<any>;
|
||||||
|
|
||||||
highLoad(): boolean;
|
highLoad(): boolean;
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ export class Postgres implements IDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async prepare(type: QueryType, query: string, params?: any[], options: QueryOption = {}): Promise<any[]> {
|
async prepare(type: QueryType, query: string, params?: any[], options: QueryOption = {}): Promise<any> {
|
||||||
// Convert query to use numbered parameters
|
// Convert query to use numbered parameters
|
||||||
let count = 1;
|
let count = 1;
|
||||||
for (let char = 0; char < query.length; char++) {
|
for (let char = 0; char < query.length; char++) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class Sqlite implements IDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line require-await
|
// eslint-disable-next-line require-await
|
||||||
async prepare(type: QueryType, query: string, params: any[] = []): Promise<any[]> {
|
async prepare(type: QueryType, query: string, params: any[] = []): Promise<any> {
|
||||||
// Logger.debug(`prepare (sqlite): type: ${type}, query: ${query}, params: ${params}`);
|
// Logger.debug(`prepare (sqlite): type: ${type}, query: ${query}, params: ${params}`);
|
||||||
const preparedQuery = this.db.prepare(Sqlite.processQuery(query));
|
const preparedQuery = this.db.prepare(Sqlite.processQuery(query));
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { isUserBanned } from "../utils/checkBan";
|
|||||||
import { HashedUserID } from "../types/user.model";
|
import { HashedUserID } from "../types/user.model";
|
||||||
import { isRequestInvalid } from "../utils/requestValidator";
|
import { isRequestInvalid } from "../utils/requestValidator";
|
||||||
|
|
||||||
function logUserNameChange(userID: string, newUserName: string, oldUserName: string, updatedByAdmin: boolean): Promise<Response> {
|
function logUserNameChange(userID: string, newUserName: string, oldUserName: string, updatedByAdmin: boolean): Promise<void> {
|
||||||
return privateDB.prepare("run",
|
return privateDB.prepare("run",
|
||||||
`INSERT INTO "userNameLogs"("userID", "newUserName", "oldUserName", "updatedByAdmin", "updatedAt") VALUES(?, ?, ?, ?, ?)`,
|
`INSERT INTO "userNameLogs"("userID", "newUserName", "oldUserName", "updatedByAdmin", "updatedAt") VALUES(?, ?, ?, ?, ?)`,
|
||||||
[userID, newUserName, oldUserName, + updatedByAdmin, new Date().getTime()]
|
[userID, newUserName, oldUserName, + updatedByAdmin, new Date().getTime()]
|
||||||
|
|||||||
Reference in New Issue
Block a user