Persistence-level interceptors for database operations.
This namespace provides interceptor pipelines specifically designed for persistence layer operations, eliminating manual observability calls and providing consistent error handling, logging, and error reporting across all database operations.
Key Benefits:
Usage: (execute-persistence-operation :find-user-by-id {:user-id user-id} db-impl-fn {:system system})
Architecture:
Persistence-level interceptors for database operations.
This namespace provides interceptor pipelines specifically designed for persistence layer operations,
eliminating manual observability calls and providing consistent error handling, logging, and
error reporting across all database operations.
Key Benefits:
- Eliminates 40+ manual observability calls from persistence methods
- Provides consistent database error handling patterns
- Automatic timing and logging for all database operations
- Single point of control for persistence-level cross-cutting concerns
Usage:
(execute-persistence-operation
:find-user-by-id
{:user-id user-id}
db-impl-fn
{:system system})
Architecture:
- Persistence interceptors wrap database operations
- Context carries operation metadata and database context
- Interceptors handle all database-related cross-cutting concerns automaticallyBase interceptor pipeline for all persistence operations.
Base interceptor pipeline for all persistence operations.
(create-persistence-context operation params db-ctx & [metadata])Creates a persistence interceptor context for database operations.
Args: operation: Keyword identifying the persistence operation (e.g., :find-user-by-id) params: Map of operation parameters db-ctx: Database context (connection, transaction info, etc) metadata: Optional additional metadata
Returns: Persistence context map with operation details and database context
Creates a persistence interceptor context for database operations. Args: operation: Keyword identifying the persistence operation (e.g., :find-user-by-id) params: Map of operation parameters db-ctx: Database context (connection, transaction info, etc) metadata: Optional additional metadata Returns: Persistence context map with operation details and database context
(create-persistence-pipeline db-logic-fn & custom-interceptors)Creates a persistence interceptor pipeline with database logic.
Args: db-logic-fn: Function that implements the actual database operation custom-interceptors: Optional additional interceptors to include
Returns: Complete interceptor pipeline for persistence operation
Creates a persistence interceptor pipeline with database logic. Args: db-logic-fn: Function that implements the actual database operation custom-interceptors: Optional additional interceptors to include Returns: Complete interceptor pipeline for persistence operation
(defpersistence name args context-map & body)Defines a persistence method with automatic interceptor pipeline.
Example: (defpersistence find-user-by-id [repo user-id] {:operation :find-user-by-id :params {:user-id user-id} :db-ctx (:ctx repo)} ;; Database logic here (let [query {:select [:*] :from [:users] :where [:= :id user-id]}] (db/execute-one! (:ctx repo) query)))
Defines a persistence method with automatic interceptor pipeline.
Example:
(defpersistence find-user-by-id [repo user-id]
{:operation :find-user-by-id
:params {:user-id user-id}
:db-ctx (:ctx repo)}
;; Database logic here
(let [query {:select [:*] :from [:users] :where [:= :id user-id]}]
(db/execute-one! (:ctx repo) query)))(execute-persistence-operation operation params db-logic-fn db-ctx & [options])Executes a persistence operation using interceptor pipeline with automatic observability.
This is the single method to use for all persistence operations. It automatically handles:
Args: operation: Keyword identifying the operation (e.g., :find-user-by-id) params: Map of operation parameters db-logic-fn: Function implementing the database operation db-ctx: Database context (connection info, etc) options: Optional map with {:custom-interceptors [...] :metadata {...}}
Returns: Result of the database operation function
Example: (execute-persistence-operation :find-user-by-id {:user-id user-id} (fn [{:keys [params db-ctx]}] ;; Database operation here (let [user-id (:user-id params)] (db/execute-one! db-ctx query))) db-ctx)
Executes a persistence operation using interceptor pipeline with automatic observability.
This is the single method to use for all persistence operations. It automatically handles:
- Debug logging for database operations
- Error handling and structured error information
- Result validation and warnings
- Operation timing and success tracking
Args:
operation: Keyword identifying the operation (e.g., :find-user-by-id)
params: Map of operation parameters
db-logic-fn: Function implementing the database operation
db-ctx: Database context (connection info, etc)
options: Optional map with {:custom-interceptors [...] :metadata {...}}
Returns:
Result of the database operation function
Example:
(execute-persistence-operation
:find-user-by-id
{:user-id user-id}
(fn [{:keys [params db-ctx]}]
;; Database operation here
(let [user-id (:user-id params)]
(db/execute-one! db-ctx query)))
db-ctx)Handles persistence operation error reporting and recovery.
Handles persistence operation error reporting and recovery.
Handles persistence operation logging throughout the lifecycle.
Handles persistence operation logging throughout the lifecycle.
Initializes persistence operation with timing and breadcrumb.
Initializes persistence operation with timing and breadcrumb.
Validates and normalizes persistence operation results.
Validates and normalizes persistence operation results.
Tracks successful persistence operations for observability.
Tracks successful persistence operations for observability.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |