/src/contrib/middleware/clsql.lisp

http://github.com/fukamachi/clack · Lisp · 81 lines · 58 code · 16 blank · 7 comment · 2 complexity · aa109b67a57c20449657c53ea8a044e3 MD5 · raw file

  1. #|
  2. This file is a part of Clack package.
  3. URL: http://github.com/fukamachi/clack
  4. Copyright (c) 2011 Eitarow Fukamachi <e.arrows@gmail.com>
  5. Clack is freely distributable under the LLGPL License.
  6. |#
  7. (clack.util:namespace clack.middleware.clsql
  8. (:use :cl
  9. :clack)
  10. (:import-from :clsql
  11. :connect
  12. :disconnect))
  13. (cl-syntax:use-syntax :annot)
  14. @export
  15. (defclass <clack-middleware-clsql> (<middleware>)
  16. ((database-type :type keyword
  17. :initarg :database-type
  18. :initform :sqlite3
  19. :accessor database-type)
  20. (connection-spec :type list
  21. :initarg :connection-spec
  22. :initform '("memory")
  23. :accessor connection-spec)
  24. (connect-args :type list
  25. :initarg :connect-args
  26. :initform nil
  27. :accessor connect-args)))
  28. (defmethod call ((this <clack-middleware-clsql>) env)
  29. (let* ((db (apply #'connect
  30. (connection-spec this)
  31. :if-exists :new
  32. :make-default nil
  33. :database-type (database-type this)
  34. (connect-args this)))
  35. (clsql:*default-database* db))
  36. (unwind-protect
  37. (call-next this env)
  38. (disconnect :database db))))
  39. (doc:start)
  40. @doc:NAME "
  41. Clack.Middleware.Clsql - Middleware for CLSQL connection management.
  42. "
  43. @doc:SYNOPSIS "
  44. (builder
  45. (<clack-middleware-clsql>
  46. :database-type :mysql
  47. :connection-spec '(\"localhost\" \"db\" \"fukamachi\" \"password\"))
  48. app)
  49. "
  50. @doc:DESCRIPTION "
  51. This is a Clack Middleware component for managing CLSQL's connection.
  52. ## Slots
  53. * database-type (Optional, Keyword)
  54. The default is `:sqlite3`.
  55. * connection-spec (Optional, List)
  56. The default is `(\"memory\")`.
  57. * connect-args (Optional, List)
  58. "
  59. @doc:AUTHOR "
  60. * Eitarow Fukamachi (e.arrows@gmail.com)
  61. "
  62. @doc:SEE "
  63. * [CLSQL](http://clsql.b9.com/)
  64. "