One DBAdapter implementation, over a per-engine spec.
There used to be four, and they were copies: each query.clj was the same
sixty lines turning on two decisions, and each core.clj was thirty lines of
delegation. A fix landed in one and not its neighbours — that is how H2 came
to carry a table-exists? workaround while SQLite and MySQL reported every
table as absent (BOU-430).
A spec names what the port says may differ between engines, and nothing else:
:label for log lines — "MySQL"
:dialect what callers dispatch on; nil means PostgreSQL
:driver JDBC driver class name
:jdbc-url (fn [db-config] -> String)
:pool HikariCP defaults
:session-statements (fn [db-config] -> seq of JDBC param vectors)
:booleans :native or :int
:string-match :like or :ilike
:table-exists? (fn [datasource table-name] -> boolean)
:table-info (fn [datasource table-name] -> vector of column maps)
:unique-keys optional (fn [datasource table-name] -> vector of column-name
vectors); without one, read from the JDBC metadata
:engine :postgresql, :mysql, :sqlite or :h2
:capabilities a subset of protocols/capability-keywords
:column-types {logical-type DDL-type} for protocols/logical-column-types;
a string is VARCHAR(length) unless :string names one type for all
:now-ms-sql SQL for the database clock in epoch millis
:on-connect optional (fn [java.sql.Connection]), run on each new
connection after the session statements
:param->db optional (fn [value] -> value) for each query parameter;
without one, instant->iso
:db->value optional (fn [value] -> value) for each value read
One `DBAdapter` implementation, over a per-engine spec.
There used to be four, and they were copies: each `query.clj` was the same
sixty lines turning on two decisions, and each `core.clj` was thirty lines of
delegation. A fix landed in one and not its neighbours — that is how H2 came
to carry a `table-exists?` workaround while SQLite and MySQL reported every
table as absent (BOU-430).
A spec names what the port says may differ between engines, and nothing else:
:label for log lines — "MySQL"
:dialect what callers dispatch on; nil means PostgreSQL
:driver JDBC driver class name
:jdbc-url (fn [db-config] -> String)
:pool HikariCP defaults
:session-statements (fn [db-config] -> seq of JDBC param vectors)
:booleans :native or :int
:string-match :like or :ilike
:table-exists? (fn [datasource table-name] -> boolean)
:table-info (fn [datasource table-name] -> vector of column maps)
:unique-keys optional (fn [datasource table-name] -> vector of column-name
vectors); without one, read from the JDBC metadata
:engine :postgresql, :mysql, :sqlite or :h2
:capabilities a subset of protocols/capability-keywords
:column-types {logical-type DDL-type} for protocols/logical-column-types;
a string is VARCHAR(length) unless :string names one type for all
:now-ms-sql SQL for the database clock in epoch millis
:on-connect optional (fn [java.sql.Connection]), run on each new
connection after the session statements
:param->db optional (fn [value] -> value) for each query parameter;
without one, `instant->iso`
:db->value optional (fn [value] -> value) for each value readCommon connection pool management utilities.
Common connection pool management utilities.
Common database operations - main coordination module.
This namespace serves as the main coordinator for common database functionality, bringing together specialized modules for different aspects of database operations that work across all adapter types.
The common functionality has been refactored into specialized namespaces:
Pure query building functions are now in wagoe.platform.core.database.query
This modular structure provides:
Common database operations - main coordination module. This namespace serves as the main coordinator for common database functionality, bringing together specialized modules for different aspects of database operations that work across all adapter types. The common functionality has been refactored into specialized namespaces: - common.connection: Connection pool management with HikariCP - common.execution: Query execution with logging and error handling - common.schema: Schema introspection and DDL execution - common.utils: Database information and convenience functions - common.core: Main coordination module (this namespace) Pure query building functions are now in wagoe.platform.core.database.query This modular structure provides: - Better organization with focused responsibilities - Easier maintenance and testing - Consistent patterns across all database adapters - Clear separation of concerns
Query execution with I/O, logging, and error handling.
This is part of the imperative shell - it performs database I/O, manages transactions, and handles side effects like logging.
Query execution with I/O, logging, and error handling. This is part of the imperative shell - it performs database I/O, manages transactions, and handles side effects like logging.
Table introspection for every adapter.
PostgreSQL, MySQL and H2 all read information_schema and differ only in
which schema predicate identifies "this database", which HoneySQL dialect
formats the query, and whether the table name may be folded to lower case.
SQLite has no information_schema and reads sqlite_master and
PRAGMA table_xinfo instead.
Both forms return the same column maps — :name (lower case), :type,
:not-null, :default, :primary-key, :generated, :generated-always,
:max-length (a character column's declared length, nil on SQLite) —
which is what the port promises and what the four separate copies did not
consistently deliver.
Table introspection for every adapter. PostgreSQL, MySQL and H2 all read `information_schema` and differ only in which schema predicate identifies "this database", which HoneySQL dialect formats the query, and whether the table name may be folded to lower case. SQLite has no `information_schema` and reads `sqlite_master` and `PRAGMA table_xinfo` instead. Both forms return the same column maps — `:name` (lower case), `:type`, `:not-null`, `:default`, `:primary-key`, `:generated`, `:generated-always`, `:max-length` (a character column's declared length, nil on SQLite) — which is what the port promises and what the four separate copies did not consistently deliver.
Common schema management and DDL utilities.
Common schema management and DDL utilities.
Common database utilities and information functions.
Common database utilities and information functions.
Configuration-driven database adapter management.
This namespace provides functionality to read database configuration from config.edn and only load adapters that are marked as :active. This allows for optimized deployments where only required database drivers are loaded.
Key Features:
Usage: (require '[wagoe.platform.shell.adapters.database.config :as db-config])
(db-config/get-active-adapters "dev") ; Get active adapters for dev env (db-config/adapter-active? :postgresql) ; Check if adapter is active
Configuration-driven database adapter management. This namespace provides functionality to read database configuration from config.edn and only load adapters that are marked as :active. This allows for optimized deployments where only required database drivers are loaded. Key Features: - Configuration-driven adapter loading - Environment-specific database configs - Graceful handling of inactive adapters - JDBC driver optimization (only load needed drivers) Usage: (require '[wagoe.platform.shell.adapters.database.config :as db-config]) (db-config/get-active-adapters "dev") ; Get active adapters for dev env (db-config/adapter-active? :postgresql) ; Check if adapter is active
Factory functions for database adapter creation and configuration.
This namespace provides convenient factory functions for creating database adapters, data sources, and database contexts. It supports multiple database types (SQLite, PostgreSQL, MySQL, H2) through a unified configuration interface.
Key Features:
Usage: (require '[wagoe.platform.shell.adapters.database.factory :as dbf])
(def ctx (dbf/db-context {:adapter :sqlite :database-path "./app.db"})) (db/execute-query! ctx {:select [:*] :from [:users]})
Factory functions for database adapter creation and configuration.
This namespace provides convenient factory functions for creating database
adapters, data sources, and database contexts. It supports multiple database
types (SQLite, PostgreSQL, MySQL, H2) through a unified configuration interface.
Key Features:
- Database adapter creation from configuration
- Connection pool and datasource management
- Database context creation with adapter + datasource
- Resource management with automatic cleanup
- Configuration validation and error handling
Usage:
(require '[wagoe.platform.shell.adapters.database.factory :as dbf])
(def ctx (dbf/db-context {:adapter :sqlite :database-path "./app.db"}))
(db/execute-query! ctx {:select [:*] :from [:users]})H2 connection settings and JDBC URL.
H2 connection settings and JDBC URL.
H2 adapter.
Runs in PostgreSQL compatibility mode with DATABASE_TO_LOWER, so identifiers behave like PostgreSQL's; native booleans; ANSI SQL.
H2 adapter. Runs in PostgreSQL compatibility mode with DATABASE_TO_LOWER, so identifiers behave like PostgreSQL's; native booleans; ANSI SQL.
MySQL connection settings and JDBC URL.
MySQL connection settings and JDBC URL.
MySQL adapter.
LIKE (case-insensitive by MySQL's default collation), booleans as TINYINT(1), and a table name that is not folded — on a case-sensitive filesystem MySQL table names are case-sensitive.
MySQL adapter. LIKE (case-insensitive by MySQL's default collation), booleans as TINYINT(1), and a table name that is not folded — on a case-sensitive filesystem MySQL table names are case-sensitive.
PostgreSQL connection settings and JDBC URL.
PostgreSQL connection settings and JDBC URL.
PostgreSQL adapter.
Case-insensitive matching with ILIKE, native booleans, and session settings carried on the JDBC URL rather than applied per connection — see postgresql.connection.
PostgreSQL adapter. Case-insensitive matching with ILIKE, native booleans, and session settings carried on the JDBC URL rather than applied per connection — see postgresql.connection.
SQLite connection settings and JDBC URL.
SQLite connection settings and JDBC URL.
SQLite adapter.
Booleans as integers, no information_schema — introspection reads sqlite_master and PRAGMA table_xinfo — and a set of PRAGMAs applied per connection, see sqlite.connection.
SQLite adapter. Booleans as integers, no information_schema — introspection reads sqlite_master and PRAGMA table_xinfo — and a set of PRAGMAs applied per connection, see sqlite.connection.
Dynamic JDBC driver loading based on active database configurations.
This namespace provides configuration-driven driver loading that eliminates the need to coordinate between configuration files and command-line aliases. Drivers are loaded dynamically based on which databases are marked as :active in the configuration files.
Key Features:
Usage: (require '[wagoe.platform.shell.adapters.database.utils.driver-loader :as dl])
;; Load drivers for active databases in current environment (dl/load-required-drivers!)
;; Load drivers for specific environment (dl/load-drivers-for-environment! "dev")
Dynamic JDBC driver loading based on active database configurations. This namespace provides configuration-driven driver loading that eliminates the need to coordinate between configuration files and command-line aliases. Drivers are loaded dynamically based on which databases are marked as :active in the configuration files. Key Features: - Single source of truth: configuration files control everything - Clear error messages when drivers are missing - Automatic driver detection from active databases - No command-line alias coordination required Usage: (require '[wagoe.platform.shell.adapters.database.utils.driver-loader :as dl]) ;; Load drivers for active databases in current environment (dl/load-required-drivers!) ;; Load drivers for specific environment (dl/load-drivers-for-environment! "dev")
Schema-to-DDL generation utilities for database adapters.
This namespace provides utilities for generating database DDL statements from Malli schema definitions. It handles:
column-typeKey Features:
Usage: (require '[wagoe.platform.shell.adapters.database.utils.schema :as schema])
(schema/generate-table-ddl ctx "users" some-malli-schema) (schema/initialize-tables-from-schemas! ctx schema-map)
Schema-to-DDL generation utilities for database adapters. This namespace provides utilities for generating database DDL statements from Malli schema definitions. It handles: - Column types, from the adapter's `column-type` - Table creation with constraints - Index generation from schema analysis - Cross-database compatibility Key Features: - Uses Malli schemas as canonical source of truth - Database-specific column type mapping - Foreign key and unique constraint generation - Automatic index creation based on field patterns Usage: (require '[wagoe.platform.shell.adapters.database.utils.schema :as schema]) (schema/generate-table-ddl ctx "users" some-malli-schema) (schema/initialize-tables-from-schemas! ctx schema-map)
CLI commands for database migration management.
Usage: clojure -M -m wagoe.platform.shell.database.cli-migrations [command] [options]
Commands: migrate - Run all pending migrations rollback - Roll back the last migration status - Show migration status create <name> - Create a new migration file reset - Drop what the app owns and migrate (dev, test, acc only) init - Initialize migration system
CLI commands for database migration management. Usage: clojure -M -m wagoe.platform.shell.database.cli-migrations [command] [options] Commands: migrate - Run all pending migrations rollback - Roll back the last migration status - Show migration status create <name> - Create a new migration file reset - Drop what the app owns and migrate (dev, test, acc only) init - Initialize migration system
CLI entry point for database seeding.
Usage: clojure -M -m wagoe.platform.shell.database.cli-seed [path]
Defaults to resources/seeds/dev.edn. Invoked by bb db:seed, which cannot
open a JDBC connection itself (libs/tools is pure Babashka), so it shells out
here — the same arrangement bb migrate uses for cli-migrations.
CLI entry point for database seeding. Usage: clojure -M -m wagoe.platform.shell.database.cli-seed [path] Defaults to resources/seeds/dev.edn. Invoked by `bb db:seed`, which cannot open a JDBC connection itself (libs/tools is pure Babashka), so it shells out here — the same arrangement `bb migrate` uses for cli-migrations.
Database migration management using Migratus.
This namespace provides functions to manage database schema migrations:
Migrations are discovered from the application's migrations/ directory and
from any library manifests published on the classpath.
Database migration management using Migratus. This namespace provides functions to manage database schema migrations: - Run pending migrations (up) - Rollback migrations (down) - Check migration status - Create new migrations Migrations are discovered from the application's `migrations/` directory and from any library manifests published on the classpath.
db:reset: drop what the application owns, then migrate.
What the application owns: every migration's objects, through the down
migrations; the tables libraries create at boot, as each declares in
wagoe/boot-tables/<lib>.edn; schema_migrations; and the schema of each
tenant in the tenants table. Nothing else in the database is touched, and
when anything else depends on what would go, nothing is dropped (BOU-585).
`db:reset`: drop what the application owns, then migrate. What the application owns: every migration's objects, through the down migrations; the tables libraries create at boot, as each declares in `wagoe/boot-tables/<lib>.edn`; `schema_migrations`; and the schema of each tenant in the `tenants` table. Nothing else in the database is touched, and when anything else depends on what would go, nothing is dropped (BOU-585).
Loads a seed file into the active database.
The pure parts — validation, kebab->snake conversion, plan building — live in
wagoe.platform.core.database.seed. This namespace owns the I/O: reading the
file, acquiring the datasource, and executing the inserts.
Loads a seed file into the active database. The pure parts — validation, kebab->snake conversion, plan building — live in `wagoe.platform.core.database.seed`. This namespace owns the I/O: reading the file, acquiring the datasource, and executing the inserts.
Widen timestamp columns declared without a timezone to ones that carry it. Text columns holding ISO-8601 instants are converted too; on SQLite, which has no type to change, their values are rewritten as epoch millis.
A column declared TIMESTAMP stores wall-clock time and no zone, so what it
means depends on who reads it. The JVM flag from BOU-431 makes every Wagoe
process agree that the zone is UTC, and this makes the column say so itself —
so a report, a psql session or another service reads the same moment.
Only PostgreSQL and H2 need it. MySQL's TIMESTAMP already normalises to UTC
on the way in and out (its zone-less type is DATETIME), and SQLite has no
timezone concept at all — its column types are storage-class affinities.
Idempotent: a column that already carries a zone is left alone, so this is safe to run from a migration and from a boot-time schema check.
Widen timestamp columns declared without a timezone to ones that carry it. Text columns holding ISO-8601 instants are converted too; on SQLite, which has no type to change, their values are rewritten as epoch millis. A column declared `TIMESTAMP` stores wall-clock time and no zone, so what it means depends on who reads it. The JVM flag from BOU-431 makes every Wagoe process agree that the zone is UTC, and this makes the column say so itself — so a report, a psql session or another service reads the same moment. Only PostgreSQL and H2 need it. MySQL's `TIMESTAMP` already normalises to UTC on the way in and out (its zone-less type is `DATETIME`), and SQLite has no timezone concept at all — its column types are storage-class affinities. Idempotent: a column that already carries a zone is left alone, so this is safe to run from a migration and from a boot-time schema check.
Validation functions for database contexts and configurations.
Context validation functions check data structure conformity including protocol satisfaction, which requires access to the DBAdapter protocol from the shell adapters layer.
Validation functions for database contexts and configurations. Context validation functions check data structure conformity including protocol satisfaction, which requires access to the DBAdapter protocol from the shell adapters layer.
Which library owns each framework module, and which modules a config
switches on. Pure data, here rather than in wagoe-platform so migrations
can skip switched-off modules without depending on it (BOU-934).
wagoe.platform.shell.modules re-exports all three.
Which library owns each framework module, and which modules a config switches on. Pure data, here rather than in wagoe-platform so migrations can skip switched-off modules without depending on it (BOU-934). `wagoe.platform.shell.modules` re-exports all three.
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 |