/** * Database column wrapper that provides type-safe query operations * while automatically unwrapping to the underlying type in results * * DbColumn implements the FieldRef interface so it can be used in conditions */ export declare class DbColumn { /** @internal */ readonly __isDbColumn = true; /** @internal */ readonly __fieldName: string; /** @internal */ readonly __dbColumnName: string; /** @internal */ readonly __valueType: TValue; constructor( /** @internal */ columnName: string); /** * This is a compile-time only type - at runtime this is never called * The actual value is returned by the query execution */ valueOf(): TValue; } /** * Type helper to detect if a type is a class instance (has prototype methods) * vs a plain data object. See conditions.ts for detailed explanation. * Excludes DbColumn and SqlFragment which have valueOf but are not value types. */ type IsClassInstance = T extends { __isDbColumn: true; } ? false : T extends { mapWith: any; as: any; buildSql: any; } ? false : T extends { valueOf(): infer V; } ? V extends T ? true : V extends number | string | boolean | bigint | symbol ? true : false : false; /** * Check for types with known class method signatures */ type HasClassMethods = T extends { getTime(): number; } ? true : T extends { size: number; has(value: any): boolean; } ? true : T extends { byteLength: number; } ? true : T extends { then(onfulfilled?: any): any; } ? true : T extends { message: string; name: string; } ? true : T extends { exec(string: string): any; } ? true : false; /** * Combined check for value types that should not be recursively processed */ type IsValueType = IsClassInstance extends true ? true : HasClassMethods extends true ? true : false; /** * Type helper to unwrap DbColumn types to their underlying values * Preserves class instances (Date, Map, Set, Temporal, etc.) as-is */ export type UnwrapDbColumns = T extends DbColumn ? V : T extends object ? IsValueType extends true ? T : { [K in keyof T]: T[K] extends DbColumn ? V : T[K] extends (infer U)[] | undefined ? U extends DbEntity ? UnwrapDbColumns[] : T[K] : T[K] extends DbEntity | undefined ? UnwrapDbColumns> : T[K]; } : T; /** * Helper to check if a type includes DbColumn */ type IncludesDbColumn = T extends DbColumn ? true : T extends DbColumn | undefined ? true : T extends undefined | DbColumn ? true : false; /** * Helper to unwrap DbColumn from potentially optional type */ type UnwrapOptionalDbColumn = T extends DbColumn | undefined ? V : T extends DbColumn ? V : never; /** * Type helper to extract only DbColumn properties from an entity * This is used for insert/update operations where only actual columns are needed, * excluding navigation properties */ export type ExtractDbColumns = { [K in keyof T as IncludesDbColumn extends true ? K : never]: UnwrapOptionalDbColumn; }; /** * Type helper to extract just the keys of DbColumn properties from an entity. * Returns a union of string literal types representing the column property names. * * @example * ```typescript * interface User { * id: DbColumn; * username: DbColumn; * posts: Post[]; // navigation property * } * * type UserColumnKeys = ExtractDbColumnKeys; * // Result: 'id' | 'username' * ``` */ export type ExtractDbColumnKeys = keyof ExtractDbColumns & string; /** * Type for insert data - only includes DbColumn properties, unwrapped to their values */ export type InsertData = Partial>; /** * Forward-declared SqlFragment marker (the actual class lives in `query/conditions`). * Used by `UpdateData` so an UPDATE can accept SqlFragment values for SQL expressions * (e.g. `jsonbMerge(...)` or raw `sql\`...\`` templates). */ interface _SqlFragmentMarker { buildSql: (...args: any[]) => string; readonly __valueType?: T; } /** * Type for update data - like InsertData but each value may also be a SqlFragment, * allowing in-place SQL expressions (e.g. `jsonbMerge(p.col, patch)` or `sql\`col + 1\``). */ export type UpdateData = { [K in keyof ExtractDbColumns]?: ExtractDbColumns[K] | _SqlFragmentMarker[K]>; }; /** * Type for upsert values - like InsertData but each value may also be a SqlFragment, * allowing SQL expressions to be computed inside the single INSERT ... ON CONFLICT * statement (e.g. a self-contained scalar subquery: * `sql\`(SELECT COUNT(*)::int FROM "post" WHERE "user_id" = ${userId})\``). * The computed value flows through `EXCLUDED."col"` into the DO UPDATE arm, so the * whole read-fold-write cycle stays one round trip. * * Fragments must be self-contained SQL: they render inside the VALUES tuple, where no * table alias is in scope (entity column references are not resolvable there), and * their interpolated values are parameterized as-is (column type mappers do not apply). */ export type UpsertData = UpdateData; /** * Marker to indicate DbEntity type (imported to avoid circular dependency) */ interface DbEntity { } /** * Check if a value is a DbColumn */ export declare function isDbColumn(value: any): value is DbColumn; export {}; //# sourceMappingURL=db-column.d.ts.map