Using crane with caveman.
Posted on November 22, 2015
by blasut
Crane is an non-opinionated ORM for Common Lisp. To use it with Caveman2 add it to your package-list and use
it in src/db.lisp. Follow the setup steps listed on the Crane website.
Here is an example of using Crane in an POST route with Caveman2 (this assumes that you are use
ing Crane in the web.lisp source file):
(deftable people ()
(first-name :type text)
(last-name :type text))
(defroute ("/people" :method :POST) (&key _parsed)
(create-from-plist 'people (plist-keyword-args _parsed))
"Created")
The helper creates a plist
with keywords formatted in a way that Crane requires from an alist
, which is the request params are in.
(defun plist-keyword-args (args)
(alexandria:flatten (loop for val in args
collect (list (alexandria:make-keyword (string-upcase (car val))) (cdr val)))))