weblocksでclsqlをデータストアに使う
mac+sbcl+weblocksの環境ができたので、weblocksを試す。
weblocksはclbuildで入れた。
slimeを起動して、以下のソースをC-c C-
(eval-when (:compile-toplevel :load-toplevel :execute) (require :weblocks) (require :clsql)) (defpackage #:person (:use #:common-lisp #:weblocks #:clsql)) (in-package :person) (weblocks:start-weblocks :debug t) (weblocks:defwebapp weblocks05 :prefix "/weblocks05/") (weblocks:defstore *sql-store* :clsql '("localhost" "xxx" "xxx" "xxx") :database-type :postgresql-socket) (clsql:def-view-class person() ((id :accessor id :db-kind :key :db-constraints (:not-null :unique) :type integer) (first-name :initarg :first-name :accessor first-name :db-constraints :not-null :type (clsql:varchar 20)) (last-name :initarg :last-name :accessor last-name :db-constraints :not-null :type (clsql:varchar 20)))) (ignore-errors (clsql:create-view-from-class 'person)) (Weblocks:Defview person-table-view (:type table :inherit-from '(:scaffold person)) (id :hidep t)) (weblocks:defview person-form-view (:type form :inherit-from '(:scaffold person)) (id :hidep t)) (defun init-user-session (comp) (setf (weblocks:composite-widgets comp) (make-instance 'weblocks:gridedit :name 'person-table :data-class 'person :sort '(id . :asc) :view 'person-table-view :item-form-view 'person-form-view)))
これが動きません。
clsql-fluidが入っていないみたい。
clsql-fluidはコネクションのプーリングをしてくれる、、、んだと思う。
うーん。もうめんどくさいので、weblocksのソースをいじってclsql-fluidを使わないようにした。
~/clbuild/source/weblocks/src/store/clsql/clsql.lisp
を
(defmethod open-store ((store-type (eql :clsql)) &rest args) (setf *default-caching* nil) ;; (setf *default-store* (apply #'make-instance 'fluid-database ;; :connection-spec args))) (setf *default-store* (apply #'connect args)))
~/clbuild/source/weblocks/src/store/clsql/weblocks-clsql.lisp
を
(defsystem weblocks-clsql :name "weblocks-clsql" :maintainer "Slava Akhmechet" :author "Slava Akhmechet" :licence "LLGPL" :description "A weblocks backend for clsql." ;; :depends-on (:closer-mop :metatilities :clsql :clsql-fluid :weblocks) :depends-on (:closer-mop :metatilities :clsql :weblocks) :components ((:file "clsql")))
に変更。
これでhttp://localhost:8080にアクセスすればスタートページが表示されるので、そこからstartして、weblocks05のリンクをクリックすれば動く。
clsqlでmysqlに繋がらないので、postgresにつないでる。
idは勝手にpostgresにシーケンスを作って連番を振ってくれるみたい。
~/clbuild/source/weblocks/src/store/clsql/clsql.lisp
に
(defmethod persist-object ((store database) object &key) ;; Note, we persist new objects in three steps, this should be ;; optimized into a single query later (let* ((class-name (class-name (class-of object))) (current-id (object-id object)) (sequence-name (make-symbol (concatenate 'string (symbol-name class-name) (symbol-name '#:-seq))))) (unless current-id ;; Create sequence if necessary ・・・
とあって、このへんでうまいことやってくれているようだ。
サニタイズもやってくれてるみたいで、htmlのタグを入力しても大丈夫。
ポスグレのログを見るとプリペアドステートメントは使ってない。