Skip to content

Commit

Permalink
Add alias for transaction method: batch
Browse files Browse the repository at this point in the history
  • Loading branch information
DallasHoff committed Jul 6, 2024
1 parent e7e5d15 commit f78c0ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
WorkerProxy,
ScalarUserFunction,
GetInfoMessage,
Statement,
} from './types.js';

export class SQLocal {
Expand Down Expand Up @@ -188,9 +189,7 @@ export class SQLocal {
return data;
};

protected execBatch = async (
statements: ReturnType<SQLocal['convertSqlTemplate']>[]
) => {
protected execBatch = async (statements: Statement[]) => {
const message = await this.createQuery({
type: 'batch',
statements,
Expand Down Expand Up @@ -223,9 +222,7 @@ export class SQLocal {
};

transaction = async (
passStatements: (
sql: SQLocal['convertSqlTemplate']
) => ReturnType<SQLocal['convertSqlTemplate']>[]
passStatements: (sql: SQLocal['convertSqlTemplate']) => Statement[]
) => {
const statements = passStatements(this.convertSqlTemplate);
const data = await this.execBatch(statements);
Expand All @@ -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']
Expand Down
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Worker> &
Record<string, (...args: any) => any>;

Expand All @@ -23,6 +28,7 @@ export type DatabaseInfo = {
};

export type Message = InputMessage | OutputMessage;
export type QueryKey = string;
export type OmitQueryKey<T> = T extends Message ? Omit<T, 'queryKey'> : never;

export type InputMessage =
Expand Down

0 comments on commit f78c0ac

Please sign in to comment.