Configuration-driven database adapter factory.
This namespace provides factory functions that only load database adapters that are marked as :active in the configuration files. This enables optimized deployments where only necessary JDBC drivers are loaded and initialized.
Key Features:
Usage: (require '[wagoe.platform.shell.adapters.database.config-factory :as cf])
;; Load only active adapters for current environment (cf/create-active-contexts)
;; Create specific adapter context from config (cf/create-config-context "dev" :wagoe/sqlite)
Configuration-driven database adapter factory. This namespace provides factory functions that only load database adapters that are marked as :active in the configuration files. This enables optimized deployments where only necessary JDBC drivers are loaded and initialized. Key Features: - Only loads adapters marked as :active in config.edn - Graceful error handling for inactive adapters - Environment-aware adapter loading - Automatic configuration validation - JDBC driver optimization Usage: (require '[wagoe.platform.shell.adapters.database.config-factory :as cf]) ;; Load only active adapters for current environment (cf/create-active-contexts) ;; Create specific adapter context from config (cf/create-config-context "dev" :wagoe/sqlite)
(adapter-available? adapter-type env)Check if an adapter type is available (active) in current environment
Check if an adapter type is available (active) in current environment
(adapter-supported? adapter-key)Check if adapter type is supported
Check if adapter type is supported
(create-active-adapters config)Create all active adapters from configuration (test compatibility)
Create all active adapters from configuration (test compatibility)
(create-active-contexts)(create-active-contexts env)Create database contexts for all active configurations in environment.
Args: env: Environment string (optional, defaults to detected environment)
Returns: Map of config-key -> database context
Example: (create-active-contexts "dev") ;; => {:wagoe/sqlite {:adapter ... :datasource ...}}
Create database contexts for all active configurations in environment.
Args:
env: Environment string (optional, defaults to detected environment)
Returns:
Map of config-key -> database context
Example:
(create-active-contexts "dev")
;; => {:wagoe/sqlite {:adapter ... :datasource ...}}(create-adapter adapter-key config)Create adapter instance (test compatibility function)
Create adapter instance (test compatibility function)
(create-config-adapter adapter-type env)Create database adapter from configuration if it's active.
Args: adapter-type: Keyword adapter type (:sqlite, :postgresql, :mysql, :h2) env: Environment string (e.g. 'dev', 'prod')
Returns: Database adapter implementing DBAdapter protocol
Throws: IllegalStateException if adapter is not active RuntimeException if adapter loading fails
Create database adapter from configuration if it's active. Args: adapter-type: Keyword adapter type (:sqlite, :postgresql, :mysql, :h2) env: Environment string (e.g. 'dev', 'prod') Returns: Database adapter implementing DBAdapter protocol Throws: IllegalStateException if adapter is not active RuntimeException if adapter loading fails
(create-config-context env config-key)Create database context from configuration key.
Args: env: Environment string config-key: Configuration key (e.g. :wagoe/sqlite)
Returns: Database context map {:adapter adapter :datasource datasource}
Example: (create-config-context "dev" :wagoe/sqlite)
Create database context from configuration key.
Args:
env: Environment string
config-key: Configuration key (e.g. :wagoe/sqlite)
Returns:
Database context map {:adapter adapter :datasource datasource}
Example:
(create-config-context "dev" :wagoe/sqlite)(ensure-adapter-available! adapter-type env)Ensure adapter is available, throw helpful error if not
Ensure adapter is available, throw helpful error if not
(get-active-adapter-types env)Get list of active adapter types for environment
Get list of active adapter types for environment
(get-default-context)(get-default-context env)Get default database context for environment.
Tries to find contexts in this order:
Args: env: Environment string (optional)
Returns: Database context or throws if no active adapters found
Get default database context for environment. Tries to find contexts in this order: 1. SQLite (most common for development) 2. First available active adapter Args: env: Environment string (optional) Returns: Database context or throws if no active adapters found
(health-check env)Perform health check on all active database connections.
Args: env: Environment string
Returns: Map with health check results for each active adapter
Perform health check on all active database connections. Args: env: Environment string Returns: Map with health check results for each active adapter
(list-available-adapters)List all available adapter types
List all available adapter types
(print-environment-summary env)Print comprehensive summary of database configuration for environment
Print comprehensive summary of database configuration for environment
(valid-adapter-config? adapter-key config)Validate adapter configuration (test compatibility)
Validate adapter configuration (test compatibility)
(validate-environment-config env)Validate database configuration for environment
Validate database configuration for environment
(with-config-context env config-key f)Execute function with database context from configuration.
Args: env: Environment string config-key: Configuration key (e.g. :wagoe/sqlite) f: Function that takes database context
Returns: Result of function execution
Execute function with database context from configuration. Args: env: Environment string config-key: Configuration key (e.g. :wagoe/sqlite) f: Function that takes database context Returns: Result of function execution
(with-default-context f)(with-default-context env f)Execute function with default database context for environment.
Args: env: Environment string (optional) f: Function that takes database context
Returns: Result of function execution
Execute function with default database context for environment. Args: env: Environment string (optional) f: Function that takes database context Returns: Result of function execution
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 |