config, storage: from-env for overriding settings via env-data
This commit is contained in:
parent
5b41d12756
commit
ac903f1f19
3 changed files with 16 additions and 8 deletions
|
@ -5,7 +5,7 @@
|
||||||
(defpackage :scopes/config
|
(defpackage :scopes/config
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
(:export #:base #:root #:*root* #:*current*
|
(:export #:base #:root #:*root* #:*current*
|
||||||
#:env-data #:env-keys #:env-prefix #:env-path
|
#:env-data #:env-keys #:env-prefix #:env-path #:from-env
|
||||||
#:actions #:add #:add-action #:children #:env-slots
|
#:actions #:add #:add-action #:children #:env-slots
|
||||||
#:name #:setup #:parent #:shutdown))
|
#:name #:setup #:parent #:shutdown))
|
||||||
|
|
||||||
|
@ -89,6 +89,9 @@
|
||||||
|
|
||||||
;;;; utility functions
|
;;;; utility functions
|
||||||
|
|
||||||
|
(defun from-env (key default)
|
||||||
|
(or (gethash key (env-data *root*)) default))
|
||||||
|
|
||||||
(defun hash-to-slots (ht obj slots)
|
(defun hash-to-slots (ht obj slots)
|
||||||
(if ht
|
(if ht
|
||||||
(dolist (sl slots)
|
(dolist (sl slots)
|
||||||
|
|
|
@ -3,11 +3,14 @@
|
||||||
|
|
||||||
(in-package :scopes/test-storage)
|
(in-package :scopes/test-storage)
|
||||||
|
|
||||||
(defvar postgres-connect-args
|
(config:root :env-keys '(:db-name :db-user :db-password))
|
||||||
'(:database-name "cltest" :host "localhost" :port 5432
|
|
||||||
:username "testuser" :password "secret"))
|
|
||||||
|
|
||||||
(config:root :env-keys '(db-name db-user db-password))
|
(defvar postgres-connect-args
|
||||||
|
(list :database-name (config:from-env :db-name "cltest")
|
||||||
|
:host "localhost"
|
||||||
|
:port 5432
|
||||||
|
:username (config:from-env :db-user "testuser")
|
||||||
|
:password (config:from-env :db-password "secret")))
|
||||||
|
|
||||||
(config:add :storage :class 'storage:config :setup #'storage:setup
|
(config:add :storage :class 'storage:config :setup #'storage:setup
|
||||||
:db-type :postgres
|
:db-type :postgres
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
|
|
||||||
(in-package :scopes/test-storage)
|
(in-package :scopes/test-storage)
|
||||||
|
|
||||||
(defvar sqlite-connect-args
|
(config:root :env-keys '(:db-name))
|
||||||
(list :database-name (namestring (scopes/testing:test-path "test.db" "data"))))
|
|
||||||
|
|
||||||
(config:root :env-keys '(db-name))
|
(defvar sqlite-connect-args
|
||||||
|
(list :database-name
|
||||||
|
(namestring
|
||||||
|
(scopes/testing:test-path (config:from-env :db-name "test.db") "data"))))
|
||||||
|
|
||||||
(config:add :storage :class 'storage:config :setup #'storage:setup
|
(config:add :storage :class 'storage:config :setup #'storage:setup
|
||||||
:db-type :sqlite3
|
:db-type :sqlite3
|
||||||
|
|
Loading…
Add table
Reference in a new issue