diff --git a/src/client.ts b/src/client.ts index 4e8ea4a..c8d11de 100644 --- a/src/client.ts +++ b/src/client.ts @@ -16,6 +16,7 @@ import type { WorkerProxy, ScalarUserFunction, GetInfoMessage, + Statement, } from './types.js'; export class SQLocal { @@ -188,9 +189,7 @@ export class SQLocal { return data; }; - protected execBatch = async ( - statements: ReturnType[] - ) => { + protected execBatch = async (statements: Statement[]) => { const message = await this.createQuery({ type: 'batch', statements, @@ -223,9 +222,7 @@ export class SQLocal { }; transaction = async ( - passStatements: ( - sql: SQLocal['convertSqlTemplate'] - ) => ReturnType[] + passStatements: (sql: SQLocal['convertSqlTemplate']) => Statement[] ) => { const statements = passStatements(this.convertSqlTemplate); const data = await this.execBatch(statements); @@ -235,6 +232,12 @@ export class SQLocal { }); }; + batch = async ( + passStatements: (sql: SQLocal['convertSqlTemplate']) => Statement[] + ) => { + return await this.transaction(passStatements); + }; + createCallbackFunction = async ( funcName: string, func: CallbackUserFunction['func'] diff --git a/src/types.ts b/src/types.ts index 4a236bb..786f07d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,11 +4,16 @@ export type Sqlite3 = Sqlite3Static; export type Sqlite3Db = Database; export type Sqlite3Method = 'get' | 'all' | 'run' | 'values'; export type Sqlite3StorageType = 'memory' | 'opfs'; -export type QueryKey = string; + +export type Statement = { + sql: string; + params: unknown[]; +}; export type RawResultData = { rows: unknown[] | unknown[][]; columns: string[]; }; + export type WorkerProxy = ProxyHandler & Record any>; @@ -23,6 +28,7 @@ export type DatabaseInfo = { }; export type Message = InputMessage | OutputMessage; +export type QueryKey = string; export type OmitQueryKey = T extends Message ? Omit : never; export type InputMessage =