import type { Knex } from 'knex'; /** * Supported SQL value types that can be safely parameterized. * This ensures type safety and prevents passing unsupported types to SQL queries. */ export type SupportedSQLValue = string | number | boolean | null | Date | Buffer | bigint | readonly SupportedSQLValue[] | Readonly<{ [key: string]: unknown; }>; /** * Types of bindings that can be used in SQL queries. */ export type SQLBinding> = { type: 'value'; value: SupportedSQLValue; } | { type: 'identifier'; name: string; } | { type: 'entityField'; fieldName: keyof TFields; }; /** * SQL Fragment class that safely handles parameterized queries. */ export declare class SQLFragment> { readonly sql: string; readonly bindings: readonly SQLBinding[]; constructor(sql: string, bindings: readonly SQLBinding[]); /** * Get bindings in the format expected by Knex. * Knex expects a flat array where both identifiers and values are mixed in order. * * @param getColumnForField - function that resolves an entity field name to its database column name */ getKnexBindings(getColumnForField: (fieldName: keyof TFields) => string): readonly Knex.RawBinding[]; /** * Combine SQL fragments */ append(other: SQLFragment): SQLFragment; /** * Join multiple SQL fragments with a comma separator. * Useful for combining column lists, value lists, etc. * * @param fragments - Array of SQL fragments to join * @returns - A new SQLFragment with the fragments joined by a comma and space */ static joinWithCommaSeparator>(...fragments: readonly SQLFragment[]): SQLFragment; /** * Concatenate multiple SQL fragments with space separator. * Useful for combining SQL clauses like WHERE, ORDER BY, etc. * * @example * ```ts * const where = sql`WHERE age > ${18}`; * const orderBy = sql`ORDER BY name`; * const query = SQLFragment.concat(sql`SELECT * FROM users`, where, orderBy); * // Generates: "SELECT * FROM users WHERE age > ? ORDER BY name" * ``` */ static concat>(...fragments: readonly SQLFragment[]): SQLFragment; /** * Get a debug representation of the query with values inline * WARNING: This is for debugging only. Never execute the returned string directly. */ getDebugString(): string; /** * Format a value for debug output based on its type. * Handles all SupportedSQLValue types. */ private static formatDebugValue; private static isPlainObjectForDebug; } /** * Helper for SQL identifiers (table/column names). * Stores the raw identifier name to be escaped by Knex using ?? placeholder. */ export declare class SQLIdentifier { readonly name: string; constructor(name: string); } /** * Helper for referencing entity fields that can be used in SQL queries. This allows for type-safe references to fields of an entity * and does automatic translation to DB field names. */ export declare class SQLEntityField, N extends keyof TFields> { readonly fieldName: N; constructor(fieldName: N); } /** * Helper for passing an array as a single bound parameter (e.g. for PostgreSQL's = ANY(?)). * Unlike bare arrays interpolated in the sql template (which expand to (?, ?, ?) for IN clauses), * this binds the entire array as one parameter, letting knex handle the array encoding. */ export declare class SQLArrayValue { readonly values: readonly SupportedSQLValue[]; constructor(values: readonly SupportedSQLValue[]); } /** * Helper for raw SQL that should not be parameterized * WARNING: Only use this with trusted input to avoid SQL injection */ export declare class SQLUnsafeRaw { readonly rawSql: string; constructor(rawSql: string); } /** * Create a SQL identifier (table/column name) that will be escaped by Knex using ??. * * @example * ```ts * identifier('users') // Will be escaped as "users" in PostgreSQL * identifier('my"table') // Will be escaped as "my""table" in PostgreSQL * identifier('column"; DROP TABLE users; --') // Will be safely escaped * ``` */ export declare function identifier(name: string): SQLIdentifier; /** * Create a reference to an entity field that can be used in SQL queries. This allows for type-safe references to fields of an entity * and does automatic translation to DB field names and will be escaped by Knex using ??. * * @param fieldName - The entity field name to reference. */ export declare function entityField, N extends keyof TFields>(fieldName: N): SQLEntityField; /** * Wrap an array so it is bound as a single parameter rather than expanded for IN clauses. * Generates PostgreSQL's = ANY(?) syntax. * * @example * ```ts * const statuses = ['active', 'pending']; * const query = sql`${entityField('status')} = ANY(${arrayValue(statuses)})`; * // Generates: ?? = ANY(?) with the array bound as a single parameter * ``` */ export declare function arrayValue(values: readonly SupportedSQLValue[]): SQLArrayValue; /** * Insert raw SQL that will not be parameterized * WARNING: This bypasses SQL injection protection. Only use with trusted input. * * @example * ```ts * // Dynamic column names * const sortColumn = 'created_at'; * const query = sql`ORDER BY ${unsafeRaw(sortColumn)} DESC`; * * // Dynamic SQL expressions * const query = sql`WHERE ${unsafeRaw('EXTRACT(year FROM created_at)')} = ${2024}`; * ``` */ export declare function unsafeRaw(sqlString: string): SQLUnsafeRaw; /** * Tagged template literal function for SQL queries * * @example * ```ts * const age = 18; * const query = sql`age >= ${age} AND status = ${'active'}`; * ``` */ export declare function sql>(strings: TemplateStringsArray, ...values: readonly (SupportedSQLValue | SQLFragment | SQLIdentifier | SQLUnsafeRaw | SQLEntityField | SQLArrayValue)[]): SQLFragment; type PickSupportedSQLValueKeys = { [K in keyof T]: T[K] extends SupportedSQLValue ? K : never; }[keyof T]; type PickStringValueKeys = { [K in keyof T]: T[K] extends string | null ? K : never; }[keyof T]; type JsonSerializable = string | number | boolean | null | undefined | readonly JsonSerializable[] | { readonly [key: string]: JsonSerializable; }; /** * An SQL expression that supports fluent comparison methods. * Extends SQLFragment so it can be used anywhere a SQLFragment is accepted. * The fluent methods return plain SQLFragment instances since they produce * complete conditions, not further chainable expressions. */ export declare class SQLChainableFragment, TValue extends SupportedSQLValue> extends SQLFragment { /** * Generates an equality condition (`= value`). * Automatically converts `null` to `IS NULL`. * * @param value - The value to compare against * @returns A {@link SQLFragment} representing the equality condition */ eq(value: TValue | null): SQLFragment; /** * Generates an inequality condition (`!= value`). * Automatically converts `null` to `IS NOT NULL`. * * @param value - The value to compare against * @returns A {@link SQLFragment} representing the inequality condition */ neq(value: TValue | null): SQLFragment; /** * Generates a greater-than condition (`> value`). * * @param value - The value to compare against * @returns A {@link SQLFragment} representing the condition */ gt(value: TValue): SQLFragment; /** * Generates a greater-than-or-equal-to condition (`>= value`). * * @param value - The value to compare against * @returns A {@link SQLFragment} representing the condition */ gte(value: TValue): SQLFragment; /** * Generates a less-than condition (`< value`). * * @param value - The value to compare against * @returns A {@link SQLFragment} representing the condition */ lt(value: TValue): SQLFragment; /** * Generates a less-than-or-equal-to condition (`<= value`). * * @param value - The value to compare against * @returns A {@link SQLFragment} representing the condition */ lte(value: TValue): SQLFragment; /** * Generates an `IS NULL` condition. * * @returns A {@link SQLFragment} representing the IS NULL check */ isNull(): SQLFragment; /** * Generates an `IS NOT NULL` condition. * * @returns A {@link SQLFragment} representing the IS NOT NULL check */ isNotNull(): SQLFragment; /** * Generates a case-sensitive `LIKE` condition for pattern matching. * * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) * @returns A {@link SQLFragment} representing the LIKE condition */ like(pattern: string): SQLFragment; /** * Generates a case-sensitive `NOT LIKE` condition. * * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) * @returns A {@link SQLFragment} representing the NOT LIKE condition */ notLike(pattern: string): SQLFragment; /** * Generates a case-insensitive `ILIKE` condition (PostgreSQL-specific). * * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) * @returns A {@link SQLFragment} representing the ILIKE condition */ ilike(pattern: string): SQLFragment; /** * Generates a case-insensitive `NOT ILIKE` condition (PostgreSQL-specific). * * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) * @returns A {@link SQLFragment} representing the NOT ILIKE condition */ notIlike(pattern: string): SQLFragment; /** * Generates an `IN (...)` condition. Each array element becomes a separate * bound parameter (`IN (?, ?, ?)`). * Returns `FALSE` when the values array is empty. * * @param values - The values to check membership against * @returns A {@link SQLFragment} representing the IN condition */ inArray(values: readonly TValue[]): SQLFragment; /** * Generates a `NOT IN (...)` condition. Each array element becomes a separate * bound parameter. * Returns `TRUE` when the values array is empty. * * @param values - The values to check non-membership against * @returns A {@link SQLFragment} representing the NOT IN condition */ notInArray(values: readonly TValue[]): SQLFragment; /** * Generates an `= ANY(?)` condition. Unlike {@link inArray}, the array is bound * as a single parameter, producing a consistent query shape for query metrics. * Returns `FALSE` when the values array is empty. * * @param values - The values to check membership against * @returns A {@link SQLFragment} representing the = ANY condition */ anyArray(values: readonly TValue[]): SQLFragment; /** * Generates a `BETWEEN min AND max` condition (inclusive on both ends). * * @param min - The lower bound * @param max - The upper bound * @returns A {@link SQLFragment} representing the BETWEEN condition */ between(min: TValue, max: TValue): SQLFragment; /** * Generates a `NOT BETWEEN min AND max` condition. * * @param min - The lower bound * @param max - The upper bound * @returns A {@link SQLFragment} representing the NOT BETWEEN condition */ notBetween(min: TValue, max: TValue): SQLFragment; } /** * Allowed PostgreSQL type names for the cast() helper. * Only these types can be used to prevent SQL injection through type name interpolation. */ declare const ALLOWED_CAST_TYPES: readonly ["int", "integer", "int2", "int4", "int8", "smallint", "bigint", "numeric", "decimal", "real", "double precision", "float", "float4", "float8", "text", "varchar", "char", "character varying", "boolean", "bool", "date", "time", "timestamp", "timestamptz", "interval", "json", "jsonb", "uuid", "bytea"]; /** * Allowed PostgreSQL type names for the cast() helper. * Only these types can be used to prevent SQL injection through type name interpolation. */ export type PostgresCastType = (typeof ALLOWED_CAST_TYPES)[number]; type ExtractFragmentFields = T extends SQLFragment ? F : never; type FragmentValueNullable = TFragment extends SQLChainableFragment ? TValue | null : SupportedSQLValue; type FragmentValue = TFragment extends SQLChainableFragment ? TValue : SupportedSQLValue; type FragmentValueArray = TFragment extends SQLChainableFragment ? readonly TValue[] : readonly SupportedSQLValue[]; /** * Generates an `IN (...)` condition from a fragment and array of values. * Each array element becomes a separate bound parameter. Returns `FALSE` for empty arrays. * * @param fragment - A SQLFragment or SQLChainableFragment to check * @param values - The values to check membership against */ declare function inArrayHelper>(fragment: TFragment, values: FragmentValueArray): SQLFragment>; /** * Generates an `IN (...)` condition from a field name and array of values. * Each array element becomes a separate bound parameter. Returns `FALSE` for empty arrays. * * @param fieldName - The entity field name to check * @param values - The values to check membership against */ declare function inArrayHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, values: readonly TFields[N][]): SQLFragment; /** * Generates an `= ANY(?)` condition from a fragment and array of values. * The array is bound as a single parameter for consistent query shape. Returns `FALSE` for empty arrays. * * @param fragment - A SQLFragment or SQLChainableFragment to check * @param values - The values to check membership against */ declare function anyArrayHelper>(fragment: TFragment, values: FragmentValueArray): SQLFragment>; /** * Generates an `= ANY(?)` condition from a field name and array of values. * The array is bound as a single parameter for consistent query shape. Returns `FALSE` for empty arrays. * * @param fieldName - The entity field name to check * @param values - The values to check membership against */ declare function anyArrayHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, values: readonly TFields[N][]): SQLFragment; /** * Generates a `NOT IN (...)` condition from a fragment and array of values. * Each array element becomes a separate bound parameter. Returns `TRUE` for empty arrays. * * @param fragment - A SQLFragment or SQLChainableFragment to check * @param values - The values to check non-membership against */ declare function notInArrayHelper>(fragment: TFragment, values: FragmentValueArray): SQLFragment>; /** * Generates a `NOT IN (...)` condition from a field name and array of values. * Each array element becomes a separate bound parameter. Returns `TRUE` for empty arrays. * * @param fieldName - The entity field name to check * @param values - The values to check non-membership against */ declare function notInArrayHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, values: readonly TFields[N][]): SQLFragment; /** * Generates a `BETWEEN min AND max` condition (inclusive) from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to check * @param min - The lower bound * @param max - The upper bound */ declare function betweenHelper>(fragment: TFragment, min: FragmentValue, max: FragmentValue): SQLFragment>; /** * Generates a `BETWEEN min AND max` condition (inclusive) from a field name. * * @param fieldName - The entity field name to check * @param min - The lower bound * @param max - The upper bound */ declare function betweenHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, min: TFields[N], max: TFields[N]): SQLFragment; /** * Generates a `NOT BETWEEN min AND max` condition from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to check * @param min - The lower bound * @param max - The upper bound */ declare function notBetweenHelper>(fragment: TFragment, min: FragmentValue, max: FragmentValue): SQLFragment>; /** * Generates a `NOT BETWEEN min AND max` condition from a field name. * * @param fieldName - The entity field name to check * @param min - The lower bound * @param max - The upper bound */ declare function notBetweenHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, min: TFields[N], max: TFields[N]): SQLFragment; /** * Generates a case-sensitive `LIKE` condition from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to match * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) */ declare function likeHelper>(fragment: TFragment, pattern: string): SQLFragment>; /** * Generates a case-sensitive `LIKE` condition from a field name. * * @param fieldName - The entity field name to match * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) */ declare function likeHelper, N extends PickStringValueKeys>(fieldName: N, pattern: string): SQLFragment; /** * Generates a case-sensitive `NOT LIKE` condition from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to match * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) */ declare function notLikeHelper>(fragment: TFragment, pattern: string): SQLFragment>; /** * Generates a case-sensitive `NOT LIKE` condition from a field name. * * @param fieldName - The entity field name to match * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) */ declare function notLikeHelper, N extends PickStringValueKeys>(fieldName: N, pattern: string): SQLFragment; /** * Generates a case-insensitive `ILIKE` condition from a fragment (PostgreSQL-specific). * * @param fragment - A SQLFragment or SQLChainableFragment to match * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) */ declare function ilikeHelper>(fragment: TFragment, pattern: string): SQLFragment>; /** * Generates a case-insensitive `ILIKE` condition from a field name (PostgreSQL-specific). * * @param fieldName - The entity field name to match * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) */ declare function ilikeHelper, N extends PickStringValueKeys>(fieldName: N, pattern: string): SQLFragment; /** * Generates a case-insensitive `NOT ILIKE` condition from a fragment (PostgreSQL-specific). * * @param fragment - A SQLFragment or SQLChainableFragment to match * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) */ declare function notIlikeHelper>(fragment: TFragment, pattern: string): SQLFragment>; /** * Generates a case-insensitive `NOT ILIKE` condition from a field name (PostgreSQL-specific). * * @param fieldName - The entity field name to match * @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character) */ declare function notIlikeHelper, N extends PickStringValueKeys>(fieldName: N, pattern: string): SQLFragment; /** * Generates an `IS NULL` condition from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to check */ declare function isNullHelper>(fragment: TFragment): SQLFragment>; /** * Generates an `IS NULL` condition from a field name. * * @param fieldName - The entity field name to check */ declare function isNullHelper, N extends keyof TFields>(fieldName: N): SQLFragment; /** * Generates an `IS NOT NULL` condition from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to check */ declare function isNotNullHelper>(fragment: TFragment): SQLFragment>; /** * Generates an `IS NOT NULL` condition from a field name. * * @param fieldName - The entity field name to check */ declare function isNotNullHelper, N extends keyof TFields>(fieldName: N): SQLFragment; /** * Generates an equality condition (`= value`) from a fragment. * Automatically converts `null` to `IS NULL`. * * @param fragment - A SQLFragment or SQLChainableFragment to compare * @param value - The value to compare against */ declare function eqHelper>(fragment: TFragment, value: FragmentValueNullable): SQLFragment>; /** * Generates an equality condition (`= value`) from a field name. * Automatically converts `null` to `IS NULL`. * * @param fieldName - The entity field name to compare * @param value - The value to compare against */ declare function eqHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, value: TFields[N]): SQLFragment; /** * Generates an inequality condition (`!= value`) from a fragment. * Automatically converts `null` to `IS NOT NULL`. * * @param fragment - A SQLFragment or SQLChainableFragment to compare * @param value - The value to compare against */ declare function neqHelper>(fragment: TFragment, value: FragmentValueNullable): SQLFragment>; /** * Generates an inequality condition (`!= value`) from a field name. * Automatically converts `null` to `IS NOT NULL`. * * @param fieldName - The entity field name to compare * @param value - The value to compare against */ declare function neqHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, value: TFields[N]): SQLFragment; /** * Generates a greater-than condition (`> value`) from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to compare * @param value - The value to compare against */ declare function gtHelper>(fragment: TFragment, value: FragmentValue): SQLFragment>; /** * Generates a greater-than condition (`> value`) from a field name. * * @param fieldName - The entity field name to compare * @param value - The value to compare against */ declare function gtHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, value: TFields[N]): SQLFragment; /** * Generates a greater-than-or-equal-to condition (`>= value`) from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to compare * @param value - The value to compare against */ declare function gteHelper>(fragment: TFragment, value: FragmentValue): SQLFragment>; /** * Generates a greater-than-or-equal-to condition (`>= value`) from a field name. * * @param fieldName - The entity field name to compare * @param value - The value to compare against */ declare function gteHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, value: TFields[N]): SQLFragment; /** * Generates a less-than condition (`< value`) from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to compare * @param value - The value to compare against */ declare function ltHelper>(fragment: TFragment, value: FragmentValue): SQLFragment>; /** * Generates a less-than condition (`< value`) from a field name. * * @param fieldName - The entity field name to compare * @param value - The value to compare against */ declare function ltHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, value: TFields[N]): SQLFragment; /** * Generates a less-than-or-equal-to condition (`<= value`) from a fragment. * * @param fragment - A SQLFragment or SQLChainableFragment to compare * @param value - The value to compare against */ declare function lteHelper>(fragment: TFragment, value: FragmentValue): SQLFragment>; /** * Generates a less-than-or-equal-to condition (`<= value`) from a field name. * * @param fieldName - The entity field name to compare * @param value - The value to compare against */ declare function lteHelper, N extends PickSupportedSQLValueKeys>(fieldName: N, value: TFields[N]): SQLFragment; /** * Generates a JSON contains condition (`@>`) from a fragment. * Tests whether the JSON value contains the given value. * * @param fragment - A SQLFragment or SQLChainableFragment to check * @param value - The JSON value to check containment of */ declare function jsonContainsHelper>(fragment: TFragment, value: JsonSerializable): SQLFragment>; /** * Generates a JSON contains condition (`@>`) from a field name. * Tests whether the JSON value contains the given value. * * @param fieldName - The entity field name to check * @param value - The JSON value to check containment of */ declare function jsonContainsHelper, N extends keyof TFields>(fieldName: N, value: JsonSerializable): SQLFragment; /** * Generates a JSON contained-by condition (`<@`) from a fragment. * Tests whether the JSON value is contained by the given value. * * @param fragment - A SQLFragment or SQLChainableFragment to check * @param value - The JSON value to check containment against */ declare function jsonContainedByHelper>(fragment: TFragment, value: JsonSerializable): SQLFragment>; /** * Generates a JSON contained-by condition (`<@`) from a field name. * Tests whether the JSON value is contained by the given value. * * @param fieldName - The entity field name to check * @param value - The JSON value to check containment against */ declare function jsonContainedByHelper, N extends keyof TFields>(fieldName: N, value: JsonSerializable): SQLFragment; /** * JSON path extraction (`->`) from a fragment. Returns JSON. * Returns an SQLChainableFragment for fluent chaining. * * @param fragment - A SQLFragment or SQLChainableFragment to extract from * @param path - The JSON key to extract */ declare function jsonPathHelper>(fragment: TFragment, path: string): SQLChainableFragment, SupportedSQLValue>; /** * JSON path extraction (`->`) from a field name. Returns JSON. * Returns an SQLChainableFragment for fluent chaining. * * @param fieldName - The entity field name to extract from * @param path - The JSON key to extract */ declare function jsonPathHelper, N extends keyof TFields>(fieldName: N, path: string): SQLChainableFragment; /** * JSON path text extraction (`->>`) from a fragment. Returns text. * Returns an SQLChainableFragment for fluent chaining. * * @param fragment - A SQLFragment or SQLChainableFragment to extract from * @param path - The JSON key to extract as text */ declare function jsonPathTextHelper>(fragment: TFragment, path: string): SQLChainableFragment, SupportedSQLValue>; /** * JSON path text extraction (`->>`) from a field name. Returns text. * Returns an SQLChainableFragment for fluent chaining. * * @param fieldName - The entity field name to extract from * @param path - The JSON key to extract as text */ declare function jsonPathTextHelper, N extends keyof TFields>(fieldName: N, path: string): SQLChainableFragment; /** * JSON deep path extraction (`#>`) from a fragment. Returns JSON at the specified key path. * Returns an SQLChainableFragment for fluent chaining. * * @param fragment - A SQLFragment or SQLChainableFragment to extract from * @param path - Array of keys forming the path (e.g., ['user', 'address', 'city']) */ declare function jsonDeepPathHelper>(fragment: TFragment, path: readonly string[]): SQLChainableFragment, SupportedSQLValue>; /** * JSON deep path extraction (`#>`) from a field name. Returns JSON at the specified key path. * Returns an SQLChainableFragment for fluent chaining. * * @param fieldName - The entity field name to extract from * @param path - Array of keys forming the path (e.g., ['user', 'address', 'city']) */ declare function jsonDeepPathHelper, N extends keyof TFields>(fieldName: N, path: readonly string[]): SQLChainableFragment; /** * JSON deep path text extraction (`#>>`) from a fragment. Returns text at the specified key path. * Returns an SQLChainableFragment for fluent chaining. * * @param fragment - A SQLFragment or SQLChainableFragment to extract from * @param path - Array of keys forming the path (e.g., ['user', 'address', 'city']) */ declare function jsonDeepPathTextHelper>(fragment: TFragment, path: readonly string[]): SQLChainableFragment, SupportedSQLValue>; /** * JSON deep path text extraction (`#>>`) from a field name. Returns text at the specified key path. * Returns an SQLChainableFragment for fluent chaining. * * @param fieldName - The entity field name to extract from * @param path - Array of keys forming the path (e.g., ['user', 'address', 'city']) */ declare function jsonDeepPathTextHelper, N extends keyof TFields>(fieldName: N, path: readonly string[]): SQLChainableFragment; /** * SQL type cast (`::type`) from a fragment. * Returns an SQLChainableFragment for fluent chaining. * * @param fragment - A SQLFragment or SQLChainableFragment to cast * @param typeName - The PostgreSQL type name (e.g., 'int', 'text', 'timestamptz') */ declare function castHelper>(fragment: TFragment, typeName: PostgresCastType): SQLChainableFragment, SupportedSQLValue>; /** * SQL type cast (`::type`) from a field name. * Returns an SQLChainableFragment for fluent chaining. * * @param fieldName - The entity field name to cast * @param typeName - The PostgreSQL type name (e.g., 'int', 'text', 'timestamptz') */ declare function castHelper, N extends keyof TFields>(fieldName: N, typeName: PostgresCastType): SQLChainableFragment; /** * Wraps a fragment in `LOWER()` to convert to lowercase. * Returns an SQLChainableFragment for fluent chaining. * * @param fragment - A SQLFragment or SQLChainableFragment to convert */ declare function lowerHelper>(fragment: TFragment): SQLChainableFragment, SupportedSQLValue>; /** * Wraps a field in `LOWER()` to convert to lowercase. * Returns an SQLChainableFragment for fluent chaining. * * @param fieldName - The entity field name to convert */ declare function lowerHelper, N extends PickStringValueKeys>(fieldName: N): SQLChainableFragment; /** * Wraps a fragment in `UPPER()` to convert to uppercase. * Returns an SQLChainableFragment for fluent chaining. * * @param fragment - A SQLFragment or SQLChainableFragment to convert */ declare function upperHelper>(fragment: TFragment): SQLChainableFragment, SupportedSQLValue>; /** * Wraps a field in `UPPER()` to convert to uppercase. * Returns an SQLChainableFragment for fluent chaining. * * @param fieldName - The entity field name to convert */ declare function upperHelper, N extends PickStringValueKeys>(fieldName: N): SQLChainableFragment; /** * Wraps a fragment in `TRIM()` to remove leading and trailing whitespace. * Returns an SQLChainableFragment for fluent chaining. * * @param fragment - A SQLFragment or SQLChainableFragment to trim */ declare function trimHelper>(fragment: TFragment): SQLChainableFragment, SupportedSQLValue>; /** * Wraps a field in `TRIM()` to remove leading and trailing whitespace. * Returns an SQLChainableFragment for fluent chaining. * * @param fieldName - The entity field name to trim */ declare function trimHelper, N extends PickStringValueKeys>(fieldName: N): SQLChainableFragment; /** * Common SQL helper functions for building queries. * * All methods accept either a field name (string) or a SQLFragment/SQLChainableFragment as the * first argument. When a SQLChainableFragment with a known TValue is passed (e.g. from trim, lower), * value parameters are type-checked against that TValue. * * @example * ```ts * // Field name usage * SQLExpression.eq('status', 'active') * * // SQLFragment/SQLChainableFragment usage * SQLExpression.eq(sql`${entityField('status')}`, 'active') * SQLExpression.eq(SQLExpression.trim('name'), 'hello') // value constrained to string * ``` */ export declare const SQLExpression: { /** * IN clause helper. * * @example * ```ts * SQLExpression.inArray('status', ['active', 'pending']) * SQLExpression.inArray(SQLExpression.lower('status'), ['active', 'pending']) * ``` */ inArray: typeof inArrayHelper; /** * = ANY() clause helper. Binds the array as a single parameter instead of expanding it. * Semantically equivalent to IN for most cases, but retains a consistent query shape for * query metrics. * * @example * ```ts * SQLExpression.anyArray('status', ['active', 'pending']) * ``` */ anyArray: typeof anyArrayHelper; /** * NOT IN clause helper. */ notInArray: typeof notInArrayHelper; /** * BETWEEN helper. * * @example * ```ts * SQLExpression.between('age', 18, 65) * SQLExpression.between(SQLExpression.cast('age', 'int'), 18, 65) * ``` */ between: typeof betweenHelper; /** * NOT BETWEEN helper. */ notBetween: typeof notBetweenHelper; /** * LIKE helper for case-sensitive pattern matching. * * @example * ```ts * SQLExpression.like('name', '%John%') * ``` */ like: typeof likeHelper; /** * NOT LIKE helper. */ notLike: typeof notLikeHelper; /** * ILIKE helper for case-insensitive matching (PostgreSQL-specific). */ ilike: typeof ilikeHelper; /** * NOT ILIKE helper for case-insensitive non-matching (PostgreSQL-specific). */ notIlike: typeof notIlikeHelper; /** * IS NULL check helper. */ isNull: typeof isNullHelper; /** * IS NOT NULL check helper. */ isNotNull: typeof isNotNullHelper; /** * Equality operator. Automatically converts null to IS NULL. */ eq: typeof eqHelper; /** * Inequality operator. Automatically converts null to IS NOT NULL. */ neq: typeof neqHelper; /** * Greater-than comparison operator. */ gt: typeof gtHelper; /** * Greater-than-or-equal-to comparison operator. */ gte: typeof gteHelper; /** * Less-than comparison operator. */ lt: typeof ltHelper; /** * Less-than-or-equal-to comparison operator. */ lte: typeof lteHelper; /** * JSON contains operator (\@\>). */ jsonContains: typeof jsonContainsHelper; /** * JSON contained by operator (\<\@\). */ jsonContainedBy: typeof jsonContainedByHelper; /** * JSON path extraction helper (-\>). * Returns an SQLChainableFragment so that fluent comparison methods can be chained. */ jsonPath: typeof jsonPathHelper; /** * JSON path text extraction helper (-\>\>). * Returns an SQLChainableFragment so that fluent comparison methods can be chained. */ jsonPathText: typeof jsonPathTextHelper; /** * JSON deep path extraction helper (#\>). * Extracts a JSON sub-object at the specified key path, returning jsonb. * Returns an SQLChainableFragment so that fluent comparison methods can be chained. * * @param expressionOrFieldName - A SQLFragment/SQLChainableFragment or entity field name * @param path - Array of keys forming the path (e.g., ['user', 'address', 'city']) */ jsonDeepPath: typeof jsonDeepPathHelper; /** * JSON deep path text extraction helper (#\>\>). * Extracts a JSON sub-object at the specified key path as text. * Returns an SQLChainableFragment so that fluent comparison methods can be chained. * * @param expressionOrFieldName - A SQLFragment/SQLChainableFragment or entity field name * @param path - Array of keys forming the path (e.g., ['user', 'address', 'city']) */ jsonDeepPathText: typeof jsonDeepPathTextHelper; /** * SQL type cast helper (::type). * Casts an expression or field to a PostgreSQL type. * Returns an SQLChainableFragment so that fluent comparison methods can be chained. * * @param expressionOrFieldName - A SQLFragment/SQLChainableFragment or entity field name to cast * @param typeName - The PostgreSQL type name (e.g., 'int', 'text', 'timestamptz') */ cast: typeof castHelper; /** * COALESCE helper. * Returns the first non-null value from the given expressions/values. * Returns an SQLChainableFragment so that fluent comparison methods can be chained. */ coalesce>(...args: readonly (SQLFragment | SupportedSQLValue)[]): SQLChainableFragment; /** * LOWER helper * Converts a string expression to lowercase. * Returns an SQLChainableFragment so that fluent comparison methods can be chained. */ lower: typeof lowerHelper; /** * UPPER helper * Converts a string expression to uppercase. * Returns an SQLChainableFragment so that fluent comparison methods can be chained. */ upper: typeof upperHelper; /** * TRIM helper * Removes leading and trailing whitespace from a string expression. * Returns an SQLChainableFragment so that fluent comparison methods can be chained. */ trim: typeof trimHelper; /** * Logical AND of multiple fragments */ and>(...conditions: readonly SQLFragment[]): SQLFragment; /** * Logical OR of multiple fragments */ or>(...conditions: readonly SQLFragment[]): SQLFragment; /** * Logical NOT of a fragment */ not>(condition: SQLFragment): SQLFragment; /** * Parentheses helper for grouping conditions */ group>(condition: SQLFragment): SQLFragment; }; export {};