Created
June 5, 2023 01:35
-
-
Save orisano/f4d4411fb7aed7c612405240f3767be9 to your computer and use it in GitHub Desktop.
sqlite-wams.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module "@sqlite.org/sqlite-wasm" { | |
type ColumnName = string; | |
type ColumnIndex = number; | |
type BlobType = Uint8Array | Int8Array | ArrayBuffer; | |
type BindableType = undefined | null | number | string | boolean | bigint | BlobType; | |
type ResultCode = number; | |
type SQLiteDataType = 1 /* SQLITE_INTEGER */ | |
| 2 /* SQLITE_FLOAT */ | |
| 3 /* SQLITE_TEXT */ | |
| 4 /* SQLITE_BLOB */ | |
| 5 /* SQLITE_NULL */ | |
type SQLiteDataTypes = null | number | bigint | string | Uint8Array | |
type FlexibleString = Uint8Array | Int8Array | ArrayBuffer | string[] | number | string | |
type RowObject = { [column: string]: SQLiteDataTypes } | |
type BindParams = { [param: string]: BindableType } | |
type BindArg = BindableType | BindableType[] | BindParams | |
export class Stmt { | |
db: DB | |
parameterCount: number | |
readonly columnCount: number | |
finalize(): ResultCode | undefined | |
clearBindings(): Stmt | |
reset(alsoClearBinds: boolean): Stmt | |
bind(ndx: number, arg: BindableType): Stmt | |
bind(arg: BindableType): Stmt | |
bind(arg: BindableType[]): Stmt | |
bind(arg: BindParams): Stmt | |
bindAsBlob(ndx: number, arg: undefined | null | string | BlobType): Stmt | |
bindAsBlob(arg: undefined | null | string | BlobType): Stmt | |
step(): boolean | |
stepReset(): Stmt | |
stepFinalize(): boolean | |
get(ndx: ColumnIndex, asType: SQLiteDataType): SQLiteDataTypes | |
get(ndx: ColumnIndex[]): SQLiteDataTypes[] | |
get(ndx: { [column: string]: any }): { [column: string]: SQLiteDataTypes } | |
getInt(ndx: ColumnIndex): number | bigint | |
getFloat(ndx: ColumnIndex): number | |
getString(ndx: ColumnIndex): string | |
getBlob(ndx: ColumnIndex): Uint8Array | |
getJSON(ndx: ColumnIndex): any | |
getColumnName(ndx: ColumnIndex): string | |
getColumnNames(tgt?: string[]): string[] | |
getParamIndex(name: string): number | undefined | |
} | |
export type ExecOptions = { | |
bind?: BindableType | BindableType[] | BindParams | |
saveSql?: string[] | |
columnNames?: string[] | |
} | |
export type ArrayRowMode = { | |
rowMode?: "array" | |
resultRows?: SQLiteDataTypes[][] | |
callback?: (row: SQLiteDataTypes[], stmt: Stmt) => boolean | |
} | |
export type ObjectRowMode<T> = { | |
rowMode: "object" | |
resultRows?: T[] | |
callback?: (row: T, stmt: Stmt) => boolean | |
} | |
export type ColumnRowMode<T> = T extends SQLiteDataTypes ? { | |
rowMode: ColumnIndex | `\$${ColumnName}` | |
resultRows?: T[] | |
callback?: (row: T, stmt: Stmt) => boolean | |
} : never | |
export type StmtRowMode = { | |
rowMode: "stmt" | |
callback?: (row: Stmt, stmt: Stmt) => boolean | |
} | |
export type ResultRowsExecOptions = ExecOptions & { | |
returnValue: "resultRows" | |
} | |
export type SaveSqlExecOptions = ExecOptions & { | |
returnValue: "saveSql" | |
} | |
export type ThisExecOptions = ExecOptions & { | |
returnValue?: "this" | |
} | |
export type CreateFunctionOptions = { | |
pApp?: number | bigint | |
xDestroy?: Function | |
deterministic?: boolean | |
directOnly?: boolean | |
innocuous?: boolean | |
arity?: number | |
} | |
export type CreateScalarFunctionOptions = CreateFunctionOptions & { | |
xFunc: Function | |
} | |
export type CreateAggregateFunctionOptions = CreateFunctionOptions & { | |
xStep: Function | |
xFinal: Function | |
} | |
export type CreateAggregateWindowFunctionOptions = CreateAggregateFunctionOptions & { | |
xValue: Function | |
xInverse: Function | |
} | |
export class DB { | |
isOpen(): boolean | |
affirmOpen(): DB | |
close(): undefined | |
changes(total?: boolean, sixtyFour?: boolean): number | bigint | |
dbFilename(dbName?: string): string | |
dbName(dbNumber?: number): string | |
dbVfsName(dbName?: string | number): string | |
prepare(sql: FlexibleString): Stmt | |
exec(sql: FlexibleString, opt: ThisExecOptions & ArrayRowMode): DB | |
exec<T = RowObject>(sql: FlexibleString, opt: ThisExecOptions & ObjectRowMode<T>): DB | |
exec<T = SQLiteDataTypes>(sql: FlexibleString, opt: ThisExecOptions & ColumnRowMode<T>): DB | |
exec(sql: FlexibleString, opt: ThisExecOptions & StmtRowMode): DB | |
exec(sql: FlexibleString, opt: ResultRowsExecOptions & ArrayRowMode): SQLiteDataTypes[][] | |
exec<T = RowObject>(sql: FlexibleString, opt: ResultRowsExecOptions & ObjectRowMode<T>): T[] | |
exec<T = SQLiteDataTypes>(sql: FlexibleString, opt: ResultRowsExecOptions & ColumnRowMode<T>): T[] | |
exec(sql: FlexibleString, opt: SaveSqlExecOptions & ArrayRowMode): string[] | |
exec<T = RowObject>(sql: FlexibleString, opt: SaveSqlExecOptions & ObjectRowMode<T>): string[] | |
exec<T = SQLiteDataTypes>(sql: FlexibleString, opt: SaveSqlExecOptions & ColumnRowMode<T>): string[] | |
exec(sql: FlexibleString, opt: SaveSqlExecOptions & StmtRowMode): string[] | |
exec(opt: { sql: FlexibleString } & ThisExecOptions & ArrayRowMode): DB | |
exec<T = RowObject>(opt: { sql: FlexibleString } & ThisExecOptions & ObjectRowMode<T>): DB | |
exec<T = SQLiteDataTypes>(opt: { sql: FlexibleString } & ThisExecOptions & ColumnRowMode<T>): DB | |
exec(opt: { sql: FlexibleString } & ThisExecOptions & StmtRowMode): DB | |
exec(opt: { sql: FlexibleString } & ResultRowsExecOptions & ArrayRowMode): SQLiteDataTypes[][] | |
exec<T = RowObject>(opt: { sql: FlexibleString } & ResultRowsExecOptions & ObjectRowMode<T>): T[] | |
exec<T = SQLiteDataTypes>(opt: { sql: FlexibleString } & ResultRowsExecOptions & ColumnRowMode<T>): T[] | |
exec(opt: { sql: FlexibleString } & SaveSqlExecOptions & ArrayRowMode): string[] | |
exec<T = RowObject>(opt: { sql: FlexibleString } & SaveSqlExecOptions & ObjectRowMode<T>): string[] | |
exec<T = SQLiteDataTypes>(opt: { sql: FlexibleString } & SaveSqlExecOptions & ColumnRowMode<T>): string[] | |
exec(opt: { sql: FlexibleString } & SaveSqlExecOptions & StmtRowMode): string[] | |
createFunction(options: { name: string } & CreateScalarFunctionOptions): DB | |
createFunction(options: { name: string } & CreateAggregateFunctionOptions): DB | |
createFunction(options: { name: string } & CreateAggregateWindowFunctionOptions): DB | |
createFunction(name: string, options: CreateScalarFunctionOptions): DB | |
createFunction(name: string, options: CreateAggregateFunctionOptions): DB | |
createFunction(name: string, options: CreateAggregateWindowFunctionOptions): DB | |
createFunction(name: string, xFunc: Function): DB | |
createFunction(name: string, xFunc: Function, options: CreateFunctionOptions): DB | |
selectValue<T = SQLiteDataTypes>(sql: FlexibleString, bind: BindArg, asType: SQLiteDataType): T extends SQLiteDataTypes ? T | undefined : never | |
selectValues<T = SQLiteDataTypes>(sql: FlexibleString, bind: BindArg, asType: SQLiteDataType): T extends SQLiteDataTypes ? T[] : never | |
selectArray(sql: FlexibleString, bind: BindArg): SQLiteDataTypes[] | undefined | |
selectObject<T = RowObject>(sql: FlexibleString, bind: BindArg): T | undefined | |
selectArrays(sql: FlexibleString, bind: BindArg): SQLiteDataTypes[][] | |
selectObjects<T = RowObject>(sql: FlexibleString, bind: BindArg): T[] | |
openStatementCount(): number | |
transaction<R>(callback: (DB) => R): R | |
transaction<R>(beginQualifier: string, callback: (DB) => R): R | |
savepoint<R>(callback: (DB) => R): R | |
checkRc(resultCode: ResultCode): DB | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment