diff --git a/flow-typed/npm/better-sqlite3_vx.x.x.js b/flow-typed/npm/better-sqlite3_vx.x.x.js index 1f2e8a9..8b343df 100644 --- a/flow-typed/npm/better-sqlite3_vx.x.x.js +++ b/flow-typed/npm/better-sqlite3_vx.x.x.js @@ -13,15 +13,24 @@ declare class bettersqlite3$Database { options?: bettersqlite3$Database$ConstructorOptions ): void; prepare(source: string): bettersqlite3$Statement; - exec(source: string): this; - transaction(sources: $ReadOnlyArray): bettersqlite3$Transaction; - pragma(pragma: string, simplify?: boolean): any; - checkpoint(databaseName?: string): this; - register(fn: (...args: any[]) => any): void; - register( - options: bettersqlite3$Database$RegisterOptions, + transaction(f: (...A) => R): (...A) => R; + pragma(pragma: string, options?: bettersqlite3$Database$PragmaOptions): any; + backup( + destination: string, + options?: bettersqlite3$Database$BackupOptions + ): Promise; + function(name: string, fn: (...args: any[]) => any): this; + function( + name: string, + options: bettersqlite3$Database$FunctionOptions, fn: (...args: any[]) => any - ): void; + ): this; + aggregate( + name: string, + options: bettersqlite3$Database$AggregateOptions + ): this; + loadExtension(path: strin, entryPoint?: string): this; + exec(source: string): this; close(): this; defaultSafeIntegers(toggleState?: boolean): this; @@ -29,18 +38,44 @@ declare class bettersqlite3$Database { } declare type bettersqlite3$Database$ConstructorOptions = { - +memory?: boolean, +readonly?: boolean, - +fileMustExist?: boolean + +fileMustExist?: boolean, + +timeout?: number, + +verbose?: ?(sqlText: string) => void }; -declare type bettersqlite3$Database$RegisterOptions = { - +name?: string, +declare type bettersqlite3$Database$PragmaOptions = { + +simple?: boolean +}; + +declare type bettersqlite3$Database$BackupOptions = { + +attahced?: string, + +progress?: (bettersqlite3$Database$BackupProgress) => number +}; + +declare type bettersqlite3$Database$BackupProgress = { + +totalPages: number, + +remainingPages: number +}; + +declare type bettersqlite3$Database$FunctionOptions = { +varargs?: boolean, +deterministic?: boolean, +safeIntegers?: boolean }; +// The actual contract to `aggregate` is more complicated and dynamic +// than can be expressed with Flow types. This is a "best-effort, +// happy-path" type definition that is on the right track but will not +// catch all errors. Consult the `better-sqlite3` API docs for the +// source of truth. +declare type bettersqlite3$Database$AggregateOptions = { + +step: (T, bettersqlite3$BoundValue) => T, + +inverse?: (T, bettersqlite3$BoundValue) => T, + +start?: T | (() => T), + +result?: (T) => bettersqlite3$BoundValue +}; + // Functions that accept bound parameters take positional parameters, // named parameters (passed as an object), or a combination of the two. // The named parameters can be placed anywhere in the argument list, but @@ -72,25 +107,15 @@ declare class bettersqlite3$Statement { all(...params: bettersqlite3$BoundParameter[]): any[]; iterate(...params: bettersqlite3$BoundParameter[]): Iterator; pluck(toggleState?: boolean): this; + expand(toggleState?: boolean): this; + raw(toggleState?: boolean): this; + columns(toggleState?: boolean): this; bind(...params: bettersqlite3$BoundParameter[]): this; safeIntegers(toggleState?: boolean): this; } -declare class bettersqlite3$Transaction { - +database: bettersqlite3$Database; - +source: string; - - constructor(db: bettersqlite3$Database, sources: string[]): void; - run(...params: any[]): bettersqlite3$RunResult; - bind(...params: any[]): this; - safeIntegers(toggleState?: boolean): this; -} - declare interface bettersqlite3$RunResult { changes: number; - // TODO: This is actually `Integer.IntLike` from npm/integer, but we - // don't have those typedefs. For now, `number` is a good - // approximation. lastInsertRowid: number; } @@ -107,7 +132,6 @@ declare module "better-sqlite3" { declare export type BindingDictionary = bettersqlite3$BindingDictionary; declare export type BoundParameter = bettersqlite3$BoundParameter; declare export type Statement = bettersqlite3$Statement; - declare export type Transaction = bettersqlite3$Transaction; declare export type RunResult = bettersqlite3$RunResult; declare export type SqliteError = bettersqlite3$SqliteError; declare module.exports: Class;