Skip to content

Commit

Permalink
Support for return value generics (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
StringKe authored Sep 2, 2024
1 parent 493ff3b commit 6f93de9
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ type ArgumentTypes<F extends VariableArgFunction> = F extends (...args: infer A)
type ElementOf<T> = T extends Array<infer E> ? E : T;

declare namespace BetterSqlite3MultipleCiphers {
interface Statement<BindParameters extends unknown[]> {
interface Statement<BindParameters extends unknown[], Result = unknown> {
database: Database;
source: string;
reader: boolean;
readonly: boolean;
busy: boolean;

run(...params: BindParameters): Database.RunResult;
get(...params: BindParameters): unknown;
all(...params: BindParameters): unknown[];
iterate(...params: BindParameters): IterableIterator<unknown>;
get(...params: BindParameters): Result | undefined;
all(...params: BindParameters): Result[];
iterate(...params: BindParameters): IterableIterator<Result>;
pluck(toggleState?: boolean): this;
expand(toggleState?: boolean): this;
raw(toggleState?: boolean): this;
Expand Down Expand Up @@ -69,22 +69,25 @@ declare namespace BetterSqlite3MultipleCiphers {
open: boolean;
inTransaction: boolean;

prepare<BindParameters extends unknown[] | {} = unknown[]>(
prepare<BindParameters extends unknown[] | {} = unknown[], Result = unknown>(
source: string,
): BindParameters extends unknown[] ? Statement<BindParameters> : Statement<[BindParameters]>;
): BindParameters extends unknown[] ? Statement<BindParameters, Result> : Statement<[BindParameters], Result>;
transaction<F extends VariableArgFunction>(fn: F): Transaction<F>;
exec(source: string): this;
key(key: Buffer): number;
rekey(key: Buffer): number;
pragma(source: string, options?: Database.PragmaOptions): unknown;
function(name: string, cb: (...params: unknown[]) => unknown): this;
function(name: string, options: Database.RegistrationOptions, cb: (...params: unknown[]) => unknown): this;
aggregate<T>(name: string, options: Database.RegistrationOptions & {
start?: T | (() => T);
step: (total: T, next: ElementOf<T>) => T | void;
inverse?: ((total: T, dropped: T) => T) | undefined;
result?: ((total: T) => unknown) | undefined;
}): this;
aggregate<T>(
name: string,
options: Database.RegistrationOptions & {
start?: T | (() => T);
step: (total: T, next: ElementOf<T>) => T | void;
inverse?: ((total: T, dropped: T) => T) | undefined;
result?: ((total: T) => unknown) | undefined;
},
): this;
loadExtension(path: string): this;
close(): this;
defaultSafeIntegers(toggleState?: boolean): this;
Expand All @@ -95,7 +98,7 @@ declare namespace BetterSqlite3MultipleCiphers {
}

interface DatabaseConstructor {
new (filename: string | Buffer, options?: Database.Options): Database;
new(filename: string | Buffer, options?: Database.Options): Database;
(filename: string, options?: Database.Options): Database;
prototype: Database;

Expand Down Expand Up @@ -150,10 +153,9 @@ declare namespace Database {
}

type SqliteError = typeof SqliteError;
type Statement<BindParameters extends unknown[] | {} = unknown[]> = BindParameters extends unknown[]
? BetterSqlite3MultipleCiphers.Statement<BindParameters>
: BetterSqlite3MultipleCiphers.Statement<[BindParameters]>;
type ColumnDefinition = BetterSqlite3MultipleCiphers.ColumnDefinition;
type Statement<BindParameters extends unknown[] | {} = unknown[], Result = unknown> = BindParameters extends unknown[] ?
BetterSqlite3MultipleCiphers.Statement<BindParameters, Result> :
BetterSqlite3MultipleCiphers.Statement<[BindParameters], Result>;
type Transaction<T extends VariableArgFunction = VariableArgFunction> = BetterSqlite3MultipleCiphers.Transaction<T>;
type Database = BetterSqlite3MultipleCiphers.Database;
}
Expand Down

0 comments on commit 6f93de9

Please sign in to comment.