cl-2sql

Lisp to SQL compiler for Common Lisp
git clone https://logand.com/git/cl-2sql.git/
Log | Files | Refs | README | LICENSE

commit 21d61b90e19c0b8ed2bc79215d08149d4f73a17a
parent 1c91d23e6156027ab4a6b719e6a99333d84e773a
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sat, 13 Aug 2011 22:49:30 +0200

added blog-post example

Diffstat:
Mtest.lisp | 47+++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+), 0 deletions(-)

diff --git a/test.lisp b/test.lisp @@ -497,3 +497,50 @@ delete => clear affected instances from cache (look-up '(or "bookmark" "webservice" "semweb")) ;; Query for “bookmark+webservice-semweb” (look-up '(not (and "bookmark" "webservice") "semweb")))))))) + +;; http://pinterface.livejournal.com/34706.html +;; http://pinterface.livejournal.com/35042.html +;; http://pinterface.livejournal.com/35586.html +;; http://pinterface.livejournal.com/35935.html + +;; http://roeim.net/vetle/docs/cl-webapp-intro/ BLOG + +(2sql-orm:defptype title () '(2sql-orm:text 64)) +(2sql-orm:defptype body () '(2sql-orm:text 128)) +(2sql-orm:defptype timestamp () '2sql-orm::ptimestamp-with-timezone) + +(2sql-orm:defpclass blog-post () + ((title :type title :initarg :title) + (body :type body :initarg :body) + (created :type timestamp :initarg :created))) + +(defun now () + (2sql-orm::make-ptimestamp-with-timezone + :date (2sql-orm::make-pdate :y 2011 :m 8 :d 13) + :time (2sql-orm::make-ptime :hh 17 :mm 4 :ss 0 :ms 0) + :timezone nil)) + +(defun make-blog-post (title body) + (2sql-orm:make-pinstance 'blog-post :title title :body body :created (now))) + +(2sql-backend:with-postgresql-connection ("pokus" "tomas" "test123" "localhost") + (2sql-orm:with-pinstance-collector-cache () + (2sql-orm::with-psequences (oid-seq) + (2sql-orm::with-pclasses (blog-post) + (let ((p1 (make-blog-post "Hello blog world" "First post!")) + (p2 (make-blog-post "This is fun" "Common Lisp is easy!"))) + (2sql-orm:query () + `(q:select ((2sql-orm:instance blog-post x)) + (q:from (q:as blog-post x)) + (q:where (q:like x.title "%wor%"))))))))) + +#+nil +(defun save-blog-post () + "Read POST data and modify blog post." + (let ((blog-post + (get-instance-by-value 'blog-post + 'url-part (hunchentoot:query-string)))) + (setf (title blog-post) (hunchentoot:post-parameter "title")) + (setf (body blog-post) (hunchentoot:post-parameter "body")) + (setf (url-part blog-post) (make-url-part (title blog-post))) + (hunchentoot:redirect (url-part blog-post))))