/** * Write operation type definitions (Insert, Update, Delete, Upsert) */ import { ConflictAction } from './enums'; import { IWhereClause } from './query.interface'; import { ITransaction } from './transaction.interface'; import { IPreSaveOperation, IPreSaveConfig } from './presave.interface'; /** * Options for insert operations */ export interface IInsertOptions { /** Table or collection name */ table: string; /** Record(s) to insert - single object or array */ data: Record | Record[]; /** Return inserted records */ returning?: boolean; /** Columns to return (if returning is true) */ returningColumns?: string[]; /** Conflict handling configuration */ onConflict?: IOnConflictOptions; /** Environment (if not using connection context) */ env?: string; /** Product tag */ product?: string; /** Database tag */ database?: string; /** Transaction to use */ transaction?: ITransaction; /** * Pre-save operations to apply before inserting * Operations like encryption, hashing, validation, transformation */ preSave?: IPreSaveOperation[]; /** * Pre-save processor configuration */ preSaveConfig?: IPreSaveConfig; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for result caching */ cache?: string; } /** * Conflict handling options for insert */ export interface IOnConflictOptions { /** Columns to detect conflict on */ columns: string[]; /** Action to take on conflict */ action: ConflictAction | 'update' | 'ignore'; /** Columns to update on conflict (if action is 'update') */ update?: string[]; } /** * Result of an insert operation */ export interface IInsertResult { /** Inserted records (if returning: true) */ data: T[]; /** Number of inserted records */ count: number; /** IDs of inserted records */ insertedIds: any[]; } /** * Options for update operations */ export interface IUpdateOptions { /** Table or collection name */ table: string; /** Fields to update */ data: Record; /** Filter conditions - records to update */ where: IWhereClause; /** Return updated records */ returning?: boolean; /** Columns to return (if returning is true) */ returningColumns?: string[]; /** Environment (if not using connection context) */ env?: string; /** Product tag */ product?: string; /** Database tag */ database?: string; /** Transaction to use */ transaction?: ITransaction; /** * Pre-save operations to apply before updating * Operations like encryption, hashing, validation, transformation */ preSave?: IPreSaveOperation[]; /** * Pre-save processor configuration */ preSaveConfig?: IPreSaveConfig; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for result caching */ cache?: string; } /** * Update operators for special update operations * Uses lowercase naming convention to match Mongoose/MongoDB style for less adoption friction */ export interface IUpdateOperator { /** Increment value */ $inc?: number; /** Set value (explicit set) */ $set?: any; /** Unset/remove field */ $unset?: boolean; /** Multiply value */ $mul?: number; /** Set minimum (only update if new value is less than current) */ $min?: any; /** Set maximum (only update if new value is greater than current) */ $max?: any; /** Add to array */ $push?: any; /** Remove from array */ $pull?: any; /** Add unique to array (only adds if value doesn't exist) */ $addToSet?: any; /** Remove first or last element from array */ $pop?: number; /** Rename a field */ $rename?: string; /** Set on insert only */ $setOnInsert?: any; /** Current date/timestamp */ $currentDate?: boolean | { $type: 'date' | 'timestamp'; }; } /** * Result of an update operation */ export interface IUpdateResult { /** Updated records (if returning: true) */ data: T[]; /** Number of updated records */ count: number; } /** * Options for delete operations */ export interface IDeleteOptions { /** Table or collection name */ table: string; /** Filter conditions - records to delete */ where: IWhereClause; /** Return deleted records */ returning?: boolean; /** Columns to return (if returning is true) */ returningColumns?: string[]; /** Environment (if not using connection context) */ env?: string; /** Product tag */ product?: string; /** Database tag */ database?: string; /** Transaction to use */ transaction?: ITransaction; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for result caching */ cache?: string; } /** * Result of a delete operation */ export interface IDeleteResult { /** Number of deleted records */ count: number; /** Deleted records (if returning: true) */ data?: any[]; } /** * Options for upsert (insert or update) operations */ export interface IUpsertOptions { /** Table or collection name */ table: string; /** Record to insert/update */ data: Record; /** Columns to detect conflict on (unique keys) */ conflictKeys: string[]; /** Columns to update on conflict (if not specified, updates all non-conflict columns) */ updateColumns?: string[]; /** Return affected record */ returning?: boolean; /** Environment (if not using connection context) */ env?: string; /** Product tag */ product?: string; /** Database tag */ database?: string; /** Transaction to use */ transaction?: ITransaction; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for result caching */ cache?: string; } /** * Result of an upsert operation */ export interface IUpsertResult { /** Affected records */ data: T[]; /** Number of affected records */ count: number; /** Whether the operation was an insert or update */ operation: 'inserted' | 'updated'; }