import { z } from 'zod'; //#region src/transaction.d.ts /** * Very simple and yet to be improved utility function to check if a provided * Statement modifies the contents of the Database it is executed on. * * @param statement Statement to check. * * @returns Boolean indicating whether the Statement modifies the contents of * the Database it is executed on. */ declare const isWrite: (statement: Statement) => boolean; /** * Value of a parameter that is applied to a statement when it is prepared. */ type StatementParamValue = string | bigint | number | boolean | null | Record; declare const StatementParamValueSchema: z.ZodAny; /** * List of parameter values to apply to a Statement. * * @example * ```ts * const res = await database.query([ * { * sql: 'SELECT * FROM accounts WHERE id = ?;', * params: [1], * }, * ]); * ``` */ type StatementParamList = Array; declare const StatementParamListSchema: z.ZodArray; /** * Object containing a map of named parameters to apply to a Statement. * * @example * ```ts * const res = await database.query([ * { * sql: 'SELECT * FROM accounts WHERE id = $id;', * params: { id: 1 }, * }, * ]); * ``` */ type StatementParamNamed = Record; declare const StatementParamNamedSchema: z.ZodRecord; /** * Statements can be passed either as a string or as an object containing the * statement, optional parameters and method to use to execute the Statement. * * @example * ```ts * // Simple statement. * await database.query(['SELECT * FROM users;']); * ``` * * @example * ```ts * // Parameterized statement with positional parameters. * await database.query([ * { sql: 'SELECT * FROM users WHERE handle = ?;', params: ['juri'] }, * ]); * ``` * * @example * ```ts * // Parameterized statement with named parameters. * await database.query([ * { sql: 'SELECT * FROM users WHERE handle = $handle;', params: { handle: 'juri' } }, * ]); * ``` * * @example * ```ts * // Execute a Statement without returning any rows. * await database.query([ * { sql: 'DELETE FROM users WHERE handle = ?;', params: ['juri'], method: 'run' }, * ]); * ``` */ type StatementInput = string | { /** * SQL statement to execute. */ sql: string; /** * Optional parameters to apply to the Statement. * * @default `undefined` */ params?: StatementParamList | StatementParamNamed | null | undefined; /** * Method to use to execute the Statement. * * - `'all'`: Executes the Statement and returns all rows formatted as objects. * - `'run'`: Executes the Statement without returning any rows. * - `'get'`: Executes the Statement and returns the values of the first row. * - `'values'`: Executes the Statement and returns the values of all rows. * * @default `'all'` */ method?: 'all' | 'run' | 'get' | 'values' | null | undefined; }; declare const StatementInputSchema: z.ZodUnion, z.ZodRecord]>>>; method: z.ZodOptional>>>; }, z.core.$strip>]>; /** * Statement to execute on a Database. */ type Statement = { /** * SQL statement to execute. */ sql: string; /** * Optional parameters to apply to the Statement. * * @default `undefined` */ params: StatementParamList | StatementParamNamed | null; /** * Method to use to execute the Statement. * * - `'all'`: Executes the Statement and returns all rows formatted as objects. * - `'run'`: Executes the Statement without returning any rows. * - `'get'`: Executes the Statement and returns the values of the first row. * - `'values'`: Executes the Statement and returns the values of all rows. * * @default `'all'` */ method: 'all' | 'run' | 'get' | 'values'; }; declare const StatementSchema: z.ZodUnion, z.ZodRecord]>; method: z.ZodEnum<{ all: "all"; run: "run"; get: "get"; values: "values"; }>; }, z.core.$strip>]>; /** * Database row represented as an object. */ type RowObject = Record; declare const RowObjectSchema: z.ZodRecord; /** * Database row represented as an Array of values. */ type RowValues = Array; declare const RowValuesSchema: z.ZodArray; /** * Result of a Statement, containing both a reference to the Statement that was * executed and the rows returned for it. */ type StatementResult = { statement: Statement; rows: Array; }; declare const StatementResultSchema: z.ZodObject<{ statement: z.ZodUnion, z.ZodRecord]>; method: z.ZodEnum<{ all: "all"; run: "run"; get: "get"; values: "values"; }>; }, z.core.$strip>]>; rows: z.ZodUnion, z.ZodArray]>; }, z.core.$strip>; /** * Transaction to execute on a Database. * * @example * ```ts * // Simple transaction. * await database.query<[User]>([ * 'SELECT * FROM users;', * ]); * * // Transaction with mode. * await database.query<[User]>([ * 'SELECT * FROM users;', * ], { mode: 'IMMEDIATE' }); * ``` */ type TransactionInput = Array | { /** * Array of Statements to execute. */ statements: Array; /** * Mode to use for the Transaction. * * If `false`, Statements will be executed serially and **not rolled back** * upon failure. * * @default `'DEFERRED'` */ mode?: 'DEFERRED' | 'IMMEDIATE' | 'EXCLUSIVE' | false | null | undefined; }; declare const TransactionInputSchema: z.ZodUnion, z.ZodRecord]>>>; method: z.ZodOptional>>>; }, z.core.$strip>]>>, z.ZodObject<{ statements: z.ZodArray, z.ZodRecord]>>>; method: z.ZodOptional>>>; }, z.core.$strip>]>>; mode: z.ZodOptional, z.ZodLiteral<"IMMEDIATE">, z.ZodLiteral<"EXCLUSIVE">, z.ZodLiteral]>>>>; }, z.core.$strip>]>; /** * Transaction to execute on a Database. */ type Transaction = { /** * Array of Statements to execute. */ statements: Array; /** * Mode to use for the Transaction. * * If `false`, Statements will be executed serially and **not rolled back** * upon failure. * * @default `'DEFERRED'` */ mode: 'DEFERRED' | 'IMMEDIATE' | 'EXCLUSIVE' | false; }; declare const TransactionSchema: z.ZodObject<{ statements: z.ZodArray, z.ZodRecord]>; method: z.ZodEnum<{ all: "all"; run: "run"; get: "get"; values: "values"; }>; }, z.core.$strip>]>>; mode: z.ZodDefault, z.ZodLiteral<"IMMEDIATE">, z.ZodLiteral<"EXCLUSIVE">, z.ZodLiteral]>>; }, z.core.$strip>; /** * Maps a tuple of Row types to a tuple of TransactionResult types. * * @example * ```ts * type Result = TransactionResult<[Account, Product]> * // Result is [TransactionResult, TransactionResult] * ``` */ type TransactionResult> = { [K in keyof T]: StatementResult }; export { RowObjectSchema, RowValuesSchema, StatementInputSchema, StatementParamListSchema, StatementParamNamedSchema, StatementParamValueSchema, StatementResultSchema, StatementSchema, TransactionInputSchema, TransactionSchema, isWrite }; export type { RowObject, RowValues, Statement, StatementInput, StatementParamList, StatementParamNamed, StatementParamValue, StatementResult, Transaction, TransactionInput, TransactionResult };