Liking cljdoc? Tell your friends :D

wagoe.platform.shell.adapters.database.protocols

Protocol defining the common interface for database adapters.

This protocol abstracts database-specific behavior while allowing common database operations to be implemented in a shared core namespace. Each database type (SQLite, PostgreSQL, MySQL, H2) implements this protocol to provide database-specific functionality.

Design Philosophy:

  • Keep protocol narrow - prefer common behavior in core
  • Only include methods that differ between databases
  • Database-agnostic operations belong in core namespace
  • Type conversions use shared utilities where possible
Protocol defining the common interface for database adapters.

This protocol abstracts database-specific behavior while allowing 
common database operations to be implemented in a shared core namespace.
Each database type (SQLite, PostgreSQL, MySQL, H2) implements this 
protocol to provide database-specific functionality.

Design Philosophy:
- Keep protocol narrow - prefer common behavior in core
- Only include methods that differ between databases
- Database-agnostic operations belong in core namespace
- Type conversions use shared utilities where possible
raw docstring

DBAdaptercljprotocol

Protocol defining database-specific behavior for multi-database support.

Each database adapter (SQLite, PostgreSQL, MySQL, H2) implements this protocol to provide database-specific functionality while common operations are handled by the shared database core namespace.

Protocol defining database-specific behavior for multi-database support.

Each database adapter (SQLite, PostgreSQL, MySQL, H2) implements this
protocol to provide database-specific functionality while common operations
are handled by the shared database core namespace.

jdbc-driverclj

(jdbc-driver this)

Return the JDBC driver class string for this database.

Returns: String - fully qualified JDBC driver class name

Example: (jdbc-driver sqlite-adapter) ;; => "org.sqlite.JDBC"

Return the JDBC driver class string for this database.

Returns:
  String - fully qualified JDBC driver class name
  
Example:
  (jdbc-driver sqlite-adapter) ;; => "org.sqlite.JDBC"

dialectclj

(dialect this)

Return the HoneySQL dialect keyword for this database.

Returns: Keyword - :sqlite, :postgresql, :mysql, :h2, or nil (for PostgreSQL default)

Note: PostgreSQL adapter returns nil to use HoneySQL's default dialect

Example: (dialect sqlite-adapter) ;; => :sqlite (dialect postgres-adapter) ;; => nil

Return the HoneySQL dialect keyword for this database.

Returns:
  Keyword - :sqlite, :postgresql, :mysql, :h2, or nil (for PostgreSQL default)
  
Note:
  PostgreSQL adapter returns nil to use HoneySQL's default dialect
  
Example:
  (dialect sqlite-adapter) ;; => :sqlite
  (dialect postgres-adapter) ;; => nil

boolean->dbclj

(boolean->db this boolean-value)

Convert boolean value to database-specific representation.

Args: boolean-value: Boolean value (true/false/nil)

Returns: Database-specific boolean representation

  • SQLite/MySQL: 1/0
  • PostgreSQL/H2: true/false

Example: (boolean->db sqlite-adapter true) ;; => 1 (boolean->db postgres-adapter true) ;; => true

Convert boolean value to database-specific representation.

Args:
  boolean-value: Boolean value (true/false/nil)
  
Returns:
  Database-specific boolean representation
  - SQLite/MySQL: 1/0
  - PostgreSQL/H2: true/false
  
Example:
  (boolean->db sqlite-adapter true) ;; => 1
  (boolean->db postgres-adapter true) ;; => true

db->booleanclj

(db->boolean this db-value)

Convert database boolean representation to Clojure boolean.

Args: db-value: Database boolean value

Returns: Boolean - true/false

Example: (db->boolean sqlite-adapter 1) ;; => true (db->boolean postgres-adapter true) ;; => true

Convert database boolean representation to Clojure boolean.

Args:
  db-value: Database boolean value
  
Returns:
  Boolean - true/false
  
Example:
  (db->boolean sqlite-adapter 1) ;; => true
  (db->boolean postgres-adapter true) ;; => true

table-exists?clj

(table-exists? this datasource table-name)

Check if a table exists in the database.

Uses database-specific table introspection:

  • SQLite: Query sqlite_master
  • PostgreSQL: Query information_schema.tables
  • MySQL: Query information_schema.tables
  • H2: Query INFORMATION_SCHEMA.TABLES

Args: datasource: Database connection pool or connection table-name: String or keyword table name

Returns: Boolean - true if table exists

Example: (table-exists? sqlite-adapter ds :users) ;; => true

Check if a table exists in the database.

Uses database-specific table introspection:
- SQLite: Query sqlite_master
- PostgreSQL: Query information_schema.tables
- MySQL: Query information_schema.tables
- H2: Query INFORMATION_SCHEMA.TABLES

Args:
  datasource: Database connection pool or connection
  table-name: String or keyword table name
  
Returns:
  Boolean - true if table exists
  
Example:
  (table-exists? sqlite-adapter ds :users) ;; => true

build-whereclj

(build-where this filters)

Build database-specific WHERE clause conditions from filter map.

Handles database-specific differences such as:

  • PostgreSQL: Use ILIKE for case-insensitive string matching
  • Others: Use LIKE for string matching
  • Boolean handling varies by database

Args: filters: Map of field -> value filters

Returns: HoneySQL WHERE clause fragment or nil

Example: (build-where postgres-adapter {:name "john" :active true}) ;; => [:and [:ilike :name "%john%"] [:= :active true]]

Build database-specific WHERE clause conditions from filter map.

Handles database-specific differences such as:
- PostgreSQL: Use ILIKE for case-insensitive string matching
- Others: Use LIKE for string matching
- Boolean handling varies by database

Args:
  filters: Map of field -> value filters
  
Returns:
  HoneySQL WHERE clause fragment or nil
  
Example:
  (build-where postgres-adapter {:name "john" :active true})
  ;; => [:and [:ilike :name "%john%"] [:= :active true]]

jdbc-urlclj

(jdbc-url this db-config)

Generate JDBC URL string from database configuration.

Args: db-config: Database configuration map

Returns: String - JDBC URL formatted for this database type

Example: (jdbc-url postgres-adapter {:host "localhost" :port 5432 :name "mydb"}) ;; => "jdbc:postgresql://localhost:5432/mydb"

Generate JDBC URL string from database configuration.

Args:
  db-config: Database configuration map
  
Returns:
  String - JDBC URL formatted for this database type
  
Example:
  (jdbc-url postgres-adapter {:host "localhost" :port 5432 :name "mydb"})
  ;; => "jdbc:postgresql://localhost:5432/mydb"

pool-defaultsclj

(pool-defaults this)

Return default connection pool settings optimized for this database.

Returns: Map - HikariCP pool configuration defaults

Example: (pool-defaults sqlite-adapter) ;; => {:minimum-idle 1 :maximum-pool-size 5 :connection-timeout-ms 30000}

Return default connection pool settings optimized for this database.

Returns:
  Map - HikariCP pool configuration defaults
  
Example:
  (pool-defaults sqlite-adapter)
  ;; => {:minimum-idle 1 :maximum-pool-size 5 :connection-timeout-ms 30000}

init-connection!clj

(init-connection! this datasource db-config)

Initialize database connection with database-specific settings.

Performs one-time connection initialization such as:

  • SQLite: Apply PRAGMA settings
  • PostgreSQL: Set application_name, timezone
  • MySQL: Set sql_mode, timezone
  • H2: Set MODE, timezone

Args: datasource: Database connection pool or connection db-config: Database configuration map

Returns: nil - side effects only

Example: (init-connection! sqlite-adapter datasource config)

Initialize database connection with database-specific settings.

Performs one-time connection initialization such as:
- SQLite: Apply PRAGMA settings
- PostgreSQL: Set application_name, timezone
- MySQL: Set sql_mode, timezone
- H2: Set MODE, timezone

Args:
  datasource: Database connection pool or connection
  db-config: Database configuration map
  
Returns:
  nil - side effects only
  
Example:
  (init-connection! sqlite-adapter datasource config)

get-table-infoclj

(get-table-info this datasource table-name)

Get column information for a table.

Uses database-specific column introspection to return standardized column information including name, type, constraints, and primary key status.

Args: datasource: Database connection pool or connection table-name: String or keyword table name

Returns: Vector of column info maps with keys:

  • :name - column name string
  • :type - database type string
  • :not-null - boolean
  • :default - default value or nil
  • :primary-key - boolean

Example: (get-table-info sqlite-adapter ds :users) ;; => [{:name "id" :type "TEXT" :not-null true :primary-key true} ...]

Get column information for a table.

Uses database-specific column introspection to return standardized
column information including name, type, constraints, and primary key status.

Args:
  datasource: Database connection pool or connection
  table-name: String or keyword table name
  
Returns:
  Vector of column info maps with keys:
  - :name - column name string
  - :type - database type string
  - :not-null - boolean
  - :default - default value or nil
  - :primary-key - boolean
  
Example:
  (get-table-info sqlite-adapter ds :users)
  ;; => [{:name "id" :type "TEXT" :not-null true :primary-key true} ...]
sourceraw docstring

DBConfigclj

Schema for database configuration - supports embedded and server-based databases.

Embedded databases (SQLite, H2 file/memory):

  • Require :adapter and :database-path
  • database-path can be file path or 'mem:name' for H2

Server databases (PostgreSQL, MySQL, H2 server):

  • Require :adapter, :host, :port, and :name
  • Optional :username, :password, :connection-params
Schema for database configuration - supports embedded and server-based databases.

Embedded databases (SQLite, H2 file/memory):
- Require :adapter and :database-path
- database-path can be file path or 'mem:name' for H2

Server databases (PostgreSQL, MySQL, H2 server):
- Require :adapter, :host, :port, and :name
- Optional :username, :password, :connection-params
sourceraw docstring

embedded-db-config?clj

(embedded-db-config? db-config)

Check if configuration is for an embedded database (SQLite or H2 file/memory).

Args: db-config: Database configuration map

Returns: Boolean - true if embedded database configuration

Example: (embedded-db-config? {:adapter :sqlite :database-path "./app.db"}) ;; => true (embedded-db-config? {:adapter :h2 :database-path "mem:testdb"}) ;; => true

Check if configuration is for an embedded database (SQLite or H2 file/memory).

Args:
  db-config: Database configuration map

Returns:
  Boolean - true if embedded database configuration

Example:
  (embedded-db-config? {:adapter :sqlite :database-path "./app.db"}) ;; => true
  (embedded-db-config? {:adapter :h2 :database-path "mem:testdb"}) ;; => true
sourceraw docstring

EmbeddedDBConfigclj

Schema for embedded database configuration (SQLite, H2 file/memory).

Schema for embedded database configuration (SQLite, H2 file/memory).
sourceraw docstring

explain-db-configclj

(explain-db-config db-config)

Get detailed validation errors for invalid database configuration.

Args: db-config: Database configuration map

Returns: Malli explanation map or nil if valid

Example: (explain-db-config {:adapter :invalid})

Get detailed validation errors for invalid database configuration.

Args:
  db-config: Database configuration map

Returns:
  Malli explanation map or nil if valid

Example:
  (explain-db-config {:adapter :invalid})
sourceraw docstring

get-adapter-typeclj

(get-adapter-type db-config)

Get the adapter type from database configuration.

Args: db-config: Database configuration map

Returns: Keyword - :sqlite, :h2, :postgresql, or :mysql

Example: (get-adapter-type {:adapter :sqlite :database-path "./app.db"}) ;; => :sqlite

Get the adapter type from database configuration.

Args:
  db-config: Database configuration map

Returns:
  Keyword - :sqlite, :h2, :postgresql, or :mysql

Example:
  (get-adapter-type {:adapter :sqlite :database-path "./app.db"}) ;; => :sqlite
sourceraw docstring

PoolConfigclj

Schema for connection pool configuration.

Schema for connection pool configuration.
sourceraw docstring

requires-credentials?clj

(requires-credentials? db-config)

Check if the database configuration requires authentication credentials.

Args: db-config: Database configuration map

Returns: Boolean - true if database typically requires username/password

Example: (requires-credentials? {:adapter :postgresql :host "localhost"}) ;; => true (requires-credentials? {:adapter :sqlite :database-path "./app.db"}) ;; => false

Check if the database configuration requires authentication credentials.

Args:
  db-config: Database configuration map

Returns:
  Boolean - true if database typically requires username/password

Example:
  (requires-credentials? {:adapter :postgresql :host "localhost"}) ;; => true
  (requires-credentials? {:adapter :sqlite :database-path "./app.db"}) ;; => false
sourceraw docstring

server-db-config?clj

(server-db-config? db-config)

Check if configuration is for server-based database (PostgreSQL, MySQL, H2 server).

Args: db-config: Database configuration map

Returns: Boolean - true if server-based database configuration

Example: (server-db-config? {:adapter :postgresql :host "localhost" :port 5432 :name "mydb"}) ;; => true

Check if configuration is for server-based database (PostgreSQL, MySQL, H2 server).

Args:
  db-config: Database configuration map

Returns:
  Boolean - true if server-based database configuration

Example:
  (server-db-config? {:adapter :postgresql :host "localhost" :port 5432 :name "mydb"}) ;; => true
sourceraw docstring

ServerDBConfigclj

Schema for server-based database configuration (PostgreSQL, MySQL, H2 server).

Schema for server-based database configuration (PostgreSQL, MySQL, H2 server).
sourceraw docstring

valid-db-config?clj

(valid-db-config? db-config)

Check if database configuration is valid without throwing exceptions.

Args: db-config: Database configuration map

Returns: Boolean - true if configuration is valid

Example: (valid-db-config? {:adapter :sqlite :database-path "db.sqlite"}) ;; => true (valid-db-config? {:adapter :postgresql :host "localhost" :port 5432 :name "mydb"}) ;; => true

Check if database configuration is valid without throwing exceptions.

Args:
  db-config: Database configuration map

Returns:
  Boolean - true if configuration is valid

Example:
  (valid-db-config? {:adapter :sqlite :database-path "db.sqlite"}) ;; => true
  (valid-db-config? {:adapter :postgresql :host "localhost" :port 5432 :name "mydb"}) ;; => true
sourceraw docstring

validate-db-configclj

(validate-db-config db-config)

Validate database configuration against Malli schema.

Args: db-config: Database configuration map

Returns: db-config if valid

Throws: ExceptionInfo with detailed validation errors if configuration is invalid

Example: (validate-db-config {:adapter :sqlite :database-path "db.sqlite"}) (validate-db-config {:adapter :postgresql :host "localhost" :port 5432 :name "mydb"})

Validate database configuration against Malli schema.

Args:
  db-config: Database configuration map

Returns:
  db-config if valid

Throws:
  ExceptionInfo with detailed validation errors if configuration is invalid

Example:
  (validate-db-config {:adapter :sqlite :database-path "db.sqlite"})
  (validate-db-config {:adapter :postgresql :host "localhost" :port 5432 :name "mydb"})
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close