// Type definitions for better-sqlite3 7.5 // Project: https://github.com/JoshuaWise/better-sqlite3 // Definitions by: Ben Davies // Mathew Rumsey // Santiago Aguilar // Alessandro Vergani // Andrew Kaiser // Mark Stewart // Florian Stamer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.8 /// 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; busy: 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 VirtualTableOptions { rows: () => Generator; columns: string[]; parameters?: string[] | undefined; safeIntegers?: boolean | undefined; directOnly?: boolean | undefined; } interface Database { memory: boolean; readonly: boolean; name: string; open: boolean; inTransaction: boolean; prepare( source: string, ): BindParameters extends any[] ? Statement : Statement<[BindParameters]>; transaction(fn: F): Transaction; exec(source: string): this; pragma(source: string, options?: Database.PragmaOptions): any; 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; table(name: string, options: VirtualTableOptions): this; unsafeMode(unsafe?: boolean): this; serialize(options?: Database.SerializeOptions): Buffer; } interface DatabaseConstructor { new (filename: string, options?: Database.Options): Database; (filename: string, options?: Database.Options): Database; prototype: Database; 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: number | bigint; } interface Options { readonly?: boolean | undefined; fileMustExist?: boolean | undefined; timeout?: number | undefined; verbose?: ((message?: any, ...additionalArgs: any[]) => void) | undefined; nativeBinding?: string | undefined; } interface SerializeOptions { attached?: string; } interface PragmaOptions { simple?: boolean | undefined; } interface RegistrationOptions { varargs?: boolean | undefined; deterministic?: boolean | undefined; safeIntegers?: boolean | undefined; directOnly?: boolean | undefined; } interface AggregateOptions extends RegistrationOptions { start?: any; step: (total: any, next: any) => any; inverse?: ((total: any, dropped: any) => any) | undefined; result?: ((total: any) => any) | undefined; } interface BackupMetadata { totalPages: number; remainingPages: number; } interface BackupOptions { progress: (info: BackupMetadata) => number; } 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; export = Database;