|
|
@@ -14,20 +14,14 @@
|
|
|
:lists-get))
|
|
|
(in-package :chatikbot.db)
|
|
|
|
|
|
-(defvar *db-name* "db.sqlite" "SQLite database name")
|
|
|
-
|
|
|
-(defun db-path ()
|
|
|
- (merge-pathnames *db-name*
|
|
|
- (asdf:component-pathname
|
|
|
- (asdf:find-system '#:chatikbot))))
|
|
|
-
|
|
|
+(defvar *db-path* "db.sqlite" "SQLite database name")
|
|
|
(defvar *current-db* nil "Currently opened database")
|
|
|
(defvar *db-lock* (bordeaux-threads:make-recursive-lock
|
|
|
"sqlite connection lock") "Database connection lock")
|
|
|
(defmacro with-db ((db) &body body)
|
|
|
`(bordeaux-threads:with-recursive-lock-held (*db-lock*)
|
|
|
(unless *current-db*
|
|
|
- (let ((path (db-path)))
|
|
|
+ (let ((path *db-path*))
|
|
|
(log:info "Connecting to ~A" path)
|
|
|
(setf *current-db* (sqlite:connect path))
|
|
|
(sqlite:execute-non-query *current-db* "PRAGMA foreign_keys = ON")))
|