interface Connection { uri: string; } interface DriverOptions { log?: typeof console; initialise: (connection: any) => void; connections: Connection[]; } declare class Driver { protected log: typeof console; constructor(options: DriverOptions); } // Type definitions for integer 1.0 // Project: https://github.com/JoshuaWise/integer#readme // Definitions by: Ben Davies // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // This can't just be written as a simple class since Integer instances can't // be constructed by its actual constructor without throwing, but calling it as // a regular function constructs new instances just fine... declare function Integer(val: Integer.IntLike): Integer.IntClass; declare namespace Integer { type IntLike = number | string | IntClass; function fromBits(low: number, high?: number): IntClass; function fromNumber(val: number, defaultVal?: number | IntClass): IntClass; function fromString(val: string, radix?: number, defaultVal?: string | IntClass): IntClass; function isInstance(val: any): boolean; const MAX_VALUE: IntClass; const MIN_VALUE: IntClass; const ZERO: IntClass; const ONE: IntClass; const NEG_ONE: IntClass; class IntClass { low: number; high: number; constructor(val: IntLike); add(augend: IntLike): IntClass; plus(augend: IntLike): IntClass; sub(subtrahend: IntLike): IntClass; subtract(subtrahend: IntLike): IntClass; minus(subtrahend: IntLike): IntClass; mul(multiplier: IntLike): IntClass; multiply(multiplier: IntLike): IntClass; times(multiplier: IntLike): IntClass; div(divisor: IntLike): IntClass; divide(divisor: IntLike): IntClass; divideBy(divisor: IntLike): IntClass; dividedBy(divisor: IntLike): IntClass; over(divisor: IntLike): IntClass; mod(divisor: IntLike): IntClass; modulo(divisor: IntLike): IntClass; neg(): IntClass; negate(): IntClass; abs(): IntClass; absoluteValue(): IntClass; and(bits: IntLike): IntClass; or(bits: IntLike): IntClass; xor(bits: IntLike): IntClass; not(): IntClass; shl(bits: number): IntClass; shiftLeft(bits: number): IntClass; shr(bits: number): IntClass; shiftRight(bits: number): IntClass; eq(val: IntLike): boolean; equals(val: IntLike): boolean; isEqualTo(val: IntLike): boolean; neq(val: IntLike): boolean; notEquals(val: IntLike): boolean; isNotEqualTo(val: IntLike): boolean; doesNotEqual(val: IntLike): boolean; gt(val: IntLike): boolean; greaterThan(val: IntLike): boolean; isGreaterThan(val: IntLike): boolean; gte(val: IntLike): boolean; greaterThanOrEquals(val: IntLike): boolean; isGreaterThanOrEqualTo(val: IntLike): boolean; lt(val: IntLike): boolean; lessThan(val: IntLike): boolean; isLessThan(val: IntLike): boolean; lte(val: IntLike): boolean; lessThanOrEquals(val: IntLike): boolean; isLessThanOrEqualTo(val: IntLike): boolean; compare(val: IntLike): -1 | 0 | 1; bitSizeAbs(): number; isEven(): boolean; isOdd(): boolean; isPositive(): boolean; isNegative(): boolean; isZero(): boolean; isNonZero(): boolean; isNotZero(): boolean; isSafe(): boolean; isUnsafe(): boolean; toNumber(): number; toNumberUnsafe(): number; toString(radix?: number): string; valueOf(): number; } } type VariableArgFunction = (...params: any[]) => any; type ArgumentTypes = F extends (...args: infer A) => any ? A : never; declare namespace BetterSqlite3 { interface Statement { database: Database; source: string; reader: boolean; run(...params: BindParameters): Database.RunResult; get(...params: BindParameters): any; all(...params: BindParameters): any[]; iterate(...params: BindParameters): IterableIterator; pluck(toggleState?: boolean): this; expand(toggleState?: boolean): this; raw(toggleState?: boolean): this; bind(...params: BindParameters): this; columns(): ColumnDefinition[]; safeIntegers(toggleState?: boolean): this; } interface ColumnDefinition { name: string; column: string | null; table: string | null; database: string | null; type: string | null; } interface Transaction { (...params: ArgumentTypes): ReturnType; default(...params: ArgumentTypes): ReturnType; deferred(...params: ArgumentTypes): ReturnType; immediate(...params: ArgumentTypes): ReturnType; exclusive(...params: ArgumentTypes): ReturnType; } interface Database { memory: boolean; readonly: boolean; name: string; open: boolean; inTransaction: boolean; // tslint:disable-next-line no-unnecessary-generics prepare(source: string): BindParameters extends any[] ? Statement : Statement<[BindParameters]>; transaction(fn: F): Transaction; exec(source: string): this; pragma(source: string, options?: Database.PragmaOptions): any; checkpoint(databaseName?: string): this; function(name: string, cb: (...params: any[]) => any): this; function(name: string, options: Database.RegistrationOptions, cb: (...params: any[]) => any): this; aggregate(name: string, options: Database.AggregateOptions): this; loadExtension(path: string): this; close(): this; defaultSafeIntegers(toggleState?: boolean): this; backup(destinationFile: string, options?: Database.BackupOptions): Promise; } interface DatabaseConstructor { new(filename: string, options?: Database.Options): Database; (filename: string, options?: Database.Options): Database; prototype: Database; Integer: typeof Integer; SqliteError: typeof SqliteError; } } declare class SqliteError implements Error { name: string; message: string; code: string; constructor(message: string, code: string); } declare namespace Database { interface RunResult { changes: number; lastInsertRowid: Integer.IntLike; } interface Options { memory?: boolean; readonly?: boolean; fileMustExist?: boolean; timeout?: number; verbose?: (message?: any, ...additionalArgs: any[]) => void; } interface PragmaOptions { simple?: boolean; } interface RegistrationOptions { varargs?: boolean; deterministic?: boolean; safeIntegers?: boolean; } interface AggregateOptions extends RegistrationOptions { start?: any; step: (total: any, next: any) => any; inverse?: (total: any, dropped: any) => any; result?: (total: any) => any; } interface BackupMetadata { totalPages: number; remainingPages: number; } interface BackupOptions { progress: (info: BackupMetadata) => number; } type Integer = typeof Integer; type SqliteError = typeof SqliteError; type Statement = BindParameters extends any[] ? BetterSqlite3.Statement : BetterSqlite3.Statement<[BindParameters]>; type ColumnDefinition = BetterSqlite3.ColumnDefinition; type Transaction = BetterSqlite3.Transaction; type Database = BetterSqlite3.Database; } declare const Database: BetterSqlite3.DatabaseConstructor; interface SQLiteOptions extends DriverOptions { initialise: (connection: Database.Database) => void; } declare class SQLite extends Driver { connection: Database.Database; constructor(options: SQLiteOptions); protected serialiseParams(params: { [key: string]: unknown; }): { [k: string]: unknown; }; buildParamsQuery(params: any): string[]; /** * Insert a document into the database. */ insert(table: T, params: DatabaseInsert>): Promise; /** * Update a document in the database. */ update(table: T, query: Partial, params: DatabaseInsert): Promise; protected buildSelectQuery(table: T, fields?: string[], params?: Partial): Promise<{ sqlQuery: string; sqlParams: { [k: string]: unknown; }; }>; /** * Find a document in the database. */ findOne(table: T, fields?: string[], params?: Partial): Promise; /** * Find documents in the database. */ find(table: T, fields?: string[], params?: Partial): Promise; } interface MySQLOptions extends DriverOptions { } declare class MySQL extends Driver { constructor(options: MySQLOptions); } type DatabaseInsert = Pick>; interface Drivers { SQLite: SQLite; MySQL: MySQL; } declare function createDatabase(driver: 'SQLite', options: DriverOptions): Drivers['SQLite']; declare function createDatabase(driver: 'MySQL', options: DriverOptions): Drivers['MySQL']; export { createDatabase };