Skip to content

duct-framework/module.sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Duct SQL Module Build Status

A Duct module that adds Integrant keys for a HikariCP SQL database connection pool and Ragtime migrations to a configuration.

This current version is experimental and will only work with the new duct.main tool. The artifact group name has been changed to prevent accidental upgrades. The version prior to this change was: 0.6.1.

Installation

Add the following dependency to your deps.edn file:

org.duct-framework/module.sql {:mvn/version "0.8.0"}

Or to your Leiningen project file:

[org.duct-framework/module.sql "0.8.0"]

Usage

Add the :duct.module/sql key to your Duct configuration:

{:duct.module/sql {}}

This module uses the Integrant expand function to add the following keys to the configuration:

  • :duct.database.sql/hikaricp - a SQL datasource
  • :duct.migrator/ragtime - applies database migrations

This will setup a pooled database connection and a migrator that looks for a file migrations.edn in the current directory. See the documentation on Ragtime's SQL migrations for information about the syntax.

The JDBC URL is supplied via the jdbc-url var. This can be set via the --jdbc-url command line argument of duct.main, or using the JDBC_DATABASE_URL environment variable.

In the :main profile, the Ragtime migration strategy is set to :raise-error, which will raise an error if there's a conflict. In the :repl profile, the migration strategy is set to :rebase, which will attempt to roll back migrations to the conflict, then reapply them all.

When using :repl profile, this module will also add two functions to the user namespace when the system has been initiated:

  • (db) - returns the database DataSource
  • (sql stmt & params) - execute a SQL statment string

License

Copyright © 2024 James Reeves

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Duct module for working with a SQL database

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •