diff --git a/storage/storage.lisp b/storage/storage.lisp index fa28173..daa974c 100644 --- a/storage/storage.lisp +++ b/storage/storage.lisp @@ -5,8 +5,8 @@ (defpackage :scopes/storage (:use :common-lisp) (:export #:*db-config* - #:make-engine #:make-storage #:db-params - #:do-sql #:drop-table)) + #:make-engine #:make-storage + #:db-params #:do-sql #:drop-table)) (in-package :scopes/storage) @@ -30,25 +30,25 @@ (defclass storage () ((engine :initarg :engine) - (db :reader db) + (conn :reader conn) (schema))) (defun make-storage (engine) (let ((st (make-instance 'storage :engine engine)) - (db (funcall (slot-value engine 'connect)))) - (setf (slot-value st 'db) db) + (conn (funcall (slot-value engine 'connect)))) + (setf (slot-value st 'conn) conn) st)) (defun db-params (st) (slot-value (slot-value st 'engine) 'params)) -(defun do-sql (st sql) - (dbi:do-sql (db st) sql)) +(defun do-sql (st spec) + (let ((sql (sxql:yield spec))) + (print sql) + (dbi:do-sql (conn st) sql))) (defun drop-table (st tn) - (let ((sql (sxql:yield (sxql:drop-table tn :if-exists t)))) - (print sql) - (do-sql st sql))) + (do-sql st (sxql:drop-table tn :if-exists t))) ;;; backend-/driver-specific stuff diff --git a/storage/tracking.lisp b/storage/tracking.lisp index 97bbd6d..1337555 100644 --- a/storage/tracking.lisp +++ b/storage/tracking.lisp @@ -27,14 +27,11 @@ (json-type (getf params :json-type)) (hf-def (mapcar #'(lambda (x) (list x :type 'text :not-null t :default '|''|)) - head-fields)) - (sql - (sxql:yield - (sxql:make-statement :create-table table-name - (nconc - `((trackid :type ,id-type :primary-key t :not-null t)) - hf-def - `((timestamp :type timestamptz :not-null t :default current_timestamp) - (data :type ,json-type))))))) - (print sql) - (storage:do-sql st sql))) + head-fields))) + (storage:do-sql st + (sxql:make-statement :create-table table-name + (nconc + `((trackid :type ,id-type :primary-key t :not-null t)) + hf-def + `((timestamp :type timestamptz :not-null t :default current_timestamp) + (data :type ,json-type)))))))