// sql.js 类型声明

declare module 'sql.js' {
  export interface SqlValue {
    [key: string]: number | string | Uint8Array | null;
  }

  export interface QueryExecResult {
    columns: string[];
    values: (number | string | Uint8Array | null)[][];
  }

  export interface ParamsObject {
    [key: string]: number | string | Uint8Array | null;
  }

  export interface ParamsCallback {
    (params: ParamsObject): void;
  }

  export interface Database {
    run(sql: string, params?: unknown[]): Database;
    exec(sql: string, params?: unknown[]): QueryExecResult[];
    each(sql: string, params: unknown[], callback: (row: SqlValue) => void, done?: () => void): void;
    prepare(sql: string): Statement;
    export(): Uint8Array;
    close(): void;
    getRowsModified(): number;
  }

  export interface Statement {
    bind(params?: unknown[]): boolean;
    step(): boolean;
    getAsObject(params?: ParamsObject): SqlValue;
    get(params?: unknown[]): (number | string | Uint8Array | null)[];
    getColumnNames(): string[];
    run(params?: unknown[]): void;
    reset(): void;
    free(): void;
  }

  export interface SqlJsStatic {
    Database: new (data?: ArrayLike<number> | Buffer | null) => Database;
  }

  export default function initSqlJs(config?: {
    locateFile?: (path: string) => string;
  }): Promise<SqlJsStatic>;
}
