@variablesoftware/mock-d1
Version:
🎛️🗂️🧠 Mock D1 Database implementation for testing Cloudflare Workers
26 lines (25 loc) • 1.06 kB
TypeScript
import { D1TableData } from "../../types/MockD1Database";
/**
* Handles SELECT * FROM <table> [WHERE ...] statements for the mock D1 engine.
* Retrieves rows from the specified table, optionally filtered by a WHERE clause.
*
* @param sql - The SQL SELECT statement string.
* @param db - The in-memory database map.
* @param bindArgs - The named bind arguments for the statement.
* @param mode - "all" to return all matching rows, "first" to return only the first.
* @returns An object representing the result of the SELECT operation.
* @throws If the SQL statement is malformed or required bind arguments are missing.
*/
export declare function handleSelect(sql: string, db: Map<string, D1TableData>, bindArgs: Record<string, unknown>, mode: "all" | "first"): void | {
success: boolean;
results: Record<string, unknown>[];
meta: {
duration: number;
size_after: number;
rows_read: number;
rows_written: number;
last_row_id: number;
changed_db: boolean;
changes: number;
};
};