diff --git a/config.lisp b/config.lisp index e5fdf43..f470962 100644 --- a/config.lisp +++ b/config.lisp @@ -4,7 +4,7 @@ (defpackage :scopes/config (:use :common-lisp) - (:export #:base #:root #:*root* + (:export #:base #:root #:*root* #:*current* #:env-data #:env-keys #:env-prefix #:env-path #:actions #:add #:add-action #:children #:env-slots #:name #:setup #:parent #:shutdown)) diff --git a/storage/storage.lisp b/storage/storage.lisp index 1fbe9e9..e0f2ce2 100644 --- a/storage/storage.lisp +++ b/storage/storage.lisp @@ -7,9 +7,9 @@ (:local-nicknames (:config :scopes/config) (:core :scopes/core) (:alx :alexandria)) - (:export #:config - #:storage #:setup - #:params #:qualified-table-name + (:export #:config + #:storage #:params #:setup + #:qualified-table-name #:do-sql #:query #:drop-table #:normalize-keyword #:normalize-plist)) @@ -18,13 +18,10 @@ ;;;; config (defclass config (config:base) - ((config:env-slots :initform '(db-name db-user db-password)) - (db-config :reader db-config :initarg :db-config) ;to be replaced - (backend) - (db-type) - (connect-args))) - -;;;; db configurations + ((backend :reader backend :initarg :backend :initform :dbi) + (db-type :reader db-type :initarg :db-type :initform :sqlite3) + (connect-args :reader connect-args :initarg :connect-args) + (options :reader options :initarg :options :initform nil))) (defvar *db-params* '(:sqlite3 (:id-type integer :json-type json :ts-sql identity) @@ -43,9 +40,8 @@ (schema :accessor schema))) (defun setup (cfg) - (let* ((conf (db-config cfg)) - (db-type (getf conf :db-type)) - (conn-args (getf conf :connect-args)) + (let* ((db-type (db-type cfg)) + (conn-args (connect-args cfg)) (connect #'(lambda () (apply #'dbi:connect-cached db-type conn-args))) (st (make-instance 'storage @@ -54,7 +50,7 @@ (ctx (make-instance 'context :config cfg :name (config:name cfg) :storage st))) (setf (conn st) (funcall connect)) - (setf (schema st) (getf (getf conf :options) :schema)) + (setf (schema st) (getf (options cfg) :schema)) ctx)) ;;;; database (SQL) interface @@ -100,7 +96,5 @@ (push v res) (push (normalize-keyword k) res)))) -;;;; backend-/driver-specific stuff - (defun ts-string (ts) (format nil "~a" (local-time:universal-to-timestamp ts))) diff --git a/test/config-postgres.lisp b/test/config-postgres.lisp index f2ac650..2325257 100644 --- a/test/config-postgres.lisp +++ b/test/config-postgres.lisp @@ -3,19 +3,12 @@ (in-package :scopes/test-storage) -(defparameter db-config-postgres - '(:backend :dbi - :db-type :postgres - :connect-args - (:database-name "cltest" - :host "localhost" - :port 5432 - :username "testuser" - :password "secret") - :options - (:schema "testing"))) +(defvar postgres-connect-args + '(:database-name "cltest" :host "localhost" :port 5432 + :username "testuser" :password "secret")) -(config:root) +(config:root :env-keys '(db-name db-user db-password)) (config:add :storage :class 'storage:config :setup #'storage:setup - :db-config db-config-postgres) + :db-type :postgres + :connect-args postgres-connect-args) diff --git a/test/config-sqlite.lisp b/test/config-sqlite.lisp index 4a32277..1d7abf8 100644 --- a/test/config-sqlite.lisp +++ b/test/config-sqlite.lisp @@ -3,15 +3,11 @@ (in-package :scopes/test-storage) -(defparameter db-config-sqlite - `(:backend :dbi - :db-type :sqlite3 - :connect-args - (:database-name - ,(namestring (scopes/testing:test-path "test.db" "data"))) - :options nil)) +(defvar sqlite-connect-args + (list :database-name (namestring (scopes/testing:test-path "test.db" "data")))) -(config:root) +(config:root :env-keys '(db-name)) (config:add :storage :class 'storage:config :setup #'storage:setup - :db-config db-config-sqlite) + :db-type :sqlite3 + :connect-args sqlite-connect-args) diff --git a/test/test-storage.lisp b/test/test-storage.lisp index d5deeac..7a85847 100644 --- a/test/test-storage.lisp +++ b/test/test-storage.lisp @@ -9,8 +9,7 @@ (:storage :scopes/storage) (:tracking :scopes/storage/tracking) (:t :scopes/testing)) - (:export #:*db-config-test* - #:run #:run-all #:run-postgres #:run-sqlite) + (:export #:run #:run-all #:run-postgres #:run-sqlite) (:import-from :scopes/testing #:deftest #:==)) (in-package :scopes/test-storage) @@ -31,8 +30,7 @@ (defun run () (core:setup-services) - (let* ((ctx (core:find-service :storage)) - (cfg (core:config ctx))) + (let ((ctx (core:find-service :storage))) (test-track ctx) (t:show-result)))