UNPKG

forge-sql-orm

Version:

Drizzle ORM integration for Atlassian @forge/sql. Provides a custom driver, schema migration, two levels of caching (local and global via @forge/kvs), optimistic locking, and query analysis.

75 lines 2.42 kB
import { UpdateQueryResponse } from "@forge/sql"; /** * Metadata structure for Forge SQL query results. * Contains execution timing, response size, and field information. */ export type ForgeSQLMetadata = { dbExecutionTime: number; responseSize: number; fields: { catalog: string; name: string; schema: string; characterSet: number; decimals: number; table: string; orgTable: string; orgName: string; flags: number; columnType: number; columnLength: number; }[]; }; /** * Result structure for Forge SQL queries. * Contains rows data and execution metadata. */ export interface ForgeSQLResult { rows: Record<string, unknown>[] | Record<string, unknown>; metadata: ForgeSQLMetadata; } /** * Driver result structure for Drizzle ORM compatibility. */ export interface ForgeDriverResult { rows: unknown[]; insertId?: number; affectedRows?: number; } /** * Query execution method types. */ export type QueryMethod = "all" | "execute"; /** * Type guard to check if an object is an UpdateQueryResponse. * * @param obj - The object to check * @returns True if the object is an UpdateQueryResponse */ export declare function isUpdateQueryResponse(obj: unknown): obj is UpdateQueryResponse; /** * Main Forge SQL driver function for Drizzle ORM integration. * Handles DDL operations, execute operations (UPDATE/INSERT/DELETE), and select operations. * Automatically saves query execution metadata to the context for performance monitoring. * * @param query - The SQL query to execute * @param params - Query parameters (may be undefined or empty array) * @param method - Execution method ("all" for SELECT, "execute" for UPDATE/INSERT/DELETE) * @returns Promise with query results compatible with Drizzle ORM * * @throws {Error} When DDL operations are called with parameters * * @example * ```typescript * // DDL operation * await forgeDriver("CREATE TABLE users (id INT)", [], "all"); * * // SELECT operation * await forgeDriver("SELECT * FROM users WHERE id = ?", [1], "all"); * * // UPDATE operation * await forgeDriver("UPDATE users SET name = ? WHERE id = ?", ["John", 1], "execute"); * ``` */ export declare const forgeDriver: (query: string, params: unknown[] | undefined, method: QueryMethod) => Promise<ForgeDriverResult>; //# sourceMappingURL=forgeDriver.d.ts.map