Make the connection pool work maybe?

ご主人様
not manx 5 years ago
parent a31d24c28d
commit 08254eda06
Signed by: C-xC-c
GPG Key ID: F52ED472284EF2F4

@ -18,23 +18,24 @@
(defmacro dbfun (name &rest body) (defmacro dbfun (name &rest body)
`(defun ,name ,(car body) `(defun ,name ,(car body)
(clsql:with-database (db conn :database-type :mysql :pool t) (clsql:with-database (db conn :database-type :mysql :pool t)
,@(cdr body)))) ,@(cdr body))))
(defun flag-id (flag) (defun flag-id (flag)
(gethash flag *flags*)) (gethash flag *flags*))
(dbfun insert-post (post_nr board flags) (dbfun insert-post (post_nr board flags)
(clsql:execute-command (format nil "insert ignore into posts (post_nr, board) values (~a, '~a');" post_nr board)) (clsql:execute-command (format nil "insert ignore into posts (post_nr, board) values (~a, '~a');" post_nr board) :database db)
(let ((post-id (caar (clsql:query (format nil "select id from posts where post_nr = ~a and board = '~a';" post_nr board))))) (let ((post-id (caar (clsql:query (format nil "select id from posts where post_nr = ~a and board = '~a';" post_nr board) :database db))))
(clsql:execute-command (clsql:execute-command
(with-output-to-string (s) (with-output-to-string (s)
(format s "insert into postflags (post_nr, flag) values") (format s "insert into postflags (post_nr, flag) values")
(loop for flag in (butlast flags) (loop for flag in (butlast flags)
do (format s "(~a,~a)," post-id (flag-id flag))) do (format s "(~a,~a)," post-id (flag-id flag)))
(format s "(~a,~a);" post-id (flag-id (car (last flags)))))))) (format s "(~a,~a);" post-id (flag-id (car (last flags)))))
:database db)))
(dbfun get-posts (posts board) (dbfun get-posts (posts board)
(let ((result (clsql:query (format nil get-posts-sql posts board))) (let ((result (clsql:query (format nil get-posts-sql posts board) :database db))
(table (make-hash-table))) (table (make-hash-table)))
(loop for (post_nr . flag) in (reverse result) do (loop for (post_nr . flag) in (reverse result) do
(unless (gethash post_nr table) (unless (gethash post_nr table)
@ -43,4 +44,4 @@
(jojo:to-json table))) (jojo:to-json table)))
(dbfun get-flags () (dbfun get-flags ()
(clsql:query "select flags.id, flags.flag from flags")) (clsql:query "select flags.id, flags.flag from flags" :database db))

Loading…
Cancel
Save