couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "Cl-CouchDb" by NickAllen
Date Thu, 12 Jun 2008 16:46:12 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The following page has been changed by NickAllen:
http://wiki.apache.org/couchdb/Cl-CouchDb

------------------------------------------------------------------------------
   * {{{cl-couchdb-client}}} -- a client server for making requests to a CouchDB database
from Common Lisp
   * {{{cl-couchdb-view-server}}} -- a view server for programming CouchDB ["Views"] with
Common Lisp
   * {{{cl-couchdb-object-layer}}} -- a simple object layer for making {{{cl-couchdb-client}}}
easier to work with
- 
  
  = Getting =
  
@@ -118, +117 @@

  
  === Querying the View Server ===
  
- You can query views with the function{{{query-view}}}:
+ You can query views with the function {{{query-view}}}:
  
  {{{
  COUCHDB-SERVER> (query-view 'by-author-type :startkey '("foobar") :endkey '("foobar"
#()))
@@ -138, +137 @@

  39
  }}}
  
- You can query ad-hoc views with the function {{{query}}}:
+ You can create ad-hoc views with the function {{{query}}}:
  {{{
  COUCHDB-SERVER> (query 'blog '(lambda (doc) (emit (@ doc :author) (@ doc :body))) :count
2)
  (((:ID . "06672346ffc093ce68a07692a5f12db5") (:KEY . "foo")
@@ -151, +150 @@

  
  == Cl-CouchDB-Object-Layer ==
  
+ {{{Cl-CouchDB-Object-Layer}}} provides an object abstraction layer over the alists coming
in and out of the database. Most importantly, using these objects (called {{{docs}}}) allows
you to automatically validate the information coming in and out of the database (preventing
other Lispers from polluting your pristine CouchDB database with specious data ;-) )
- The objects (which are called {{{docs}}}) are in fact a thin layer over
- alists. Specifically, you can call {{{@}}} on docs to get the value of an
- attribute, exactly as you would do with an alist. CouchDB doesn't
- check in any way how the documents we put in it look like, so it
- seems a good idea to have some way of checking a document is valid
- before sending it to the database. This is why I introduced the
- concept of validators.
  
- To define a doc class, use defdoc (which is similar to defclass). For
- example:
+ === Defining Doc Classes ===
+ 
+ To define a doc class, use {{{DEFDOC}}} (which is similar to [http://www.lisp.org/HyperSpec/Body/mac_defclass.html
DEFCLASS]).
+ 
  {{{
  COUCHDB-OBJECTS> (defdoc blog-post 
  		     ((:author :validator #'stringp)
@@ -170, +165 @@

  		   (:default-db 'blog))
  #<STANDARD-METHOD MAKE ((EQL BLOG-POST)) {BEB6679}>
  }}}
- The validators are one argument functions taking the value of an
- attribute (something like a slot, but identified by a keyword) and
- returns true if it is valid. The initform may be either a normal lisp
- value or a one argument function, which is called on the object itself
- after setting other attributes.
+ 
+ "Attributes" are like slots, except identified by a keyword. Attributes can have a {{{:VALIDATOR}}}
and {{{:INITFORM}}} and {{{:DOCUMENTATION}}} attribute-options (which are liks slot-options
for CLOS objects).
+ 
+  * A {{{:VALIDATOR}}} must be a unary function that take the value of an attribute and returns
a non-{{{NULL}}} value if it is valid.
+  * An {{{:INITFORM}}} may be either a normal Lisp value or unary argument function, which
is called on the object itself after setting other attributes.
+  * a {{{:DOCUMENTATION}}} attribute-option is a doc string.
+ 
+ === Making Docs ===
+ 
+ Use the function {{{MAKE}}} to make {{{DOC}}}s. {{{MAKE}}} is something like [http://www.lisp.org/HyperSpec/Body/stagenfun_make-instance.html
MAKE-INSTANCE].
+ 
  {{{
  COUCHDB-OBJECTS> (make 'blog-post :author "Kuba" :title "O czym dziś napisać" :body
"Foo")
  #<doc(NIL) :_ID "o_czym_dzis_napisac" :BODY "Foo" :TITLE "O czym dziś napisać" :AUTHOR
"Kuba" :TYPE "BLOG-POST">
+ }}}
  
+ === Getting Data from Docs ===
+ 
+ You can call {{{@}}} on docs to get the value of an attribute, exactly as you would call
{{{@}}} on an alist.
+ 
+ {{{
  COUCHDB-OBJECTS> (let ((doc (make 'blog-post :author "Kuba" :title "O czym dziś napisać"
:body "Foo")))
  		   (@ doc :title))
  "O czym dziś napisać"
  }}}
+ 
+ === Saving Docs ===
+ 
- We can call make-and-save to create a document and save it in the
+ We can call {{{make-and-save}}} to create a document and save it in the database:
- database:
+ 
  {{{
  COUCHDB-OBJECTS> (make-and-save 'blog-post :author "Kuba" :title "Zażółć gęślą
jaźń" :body "foobar") ;we'll get the rev in return
  "2591270477"
  }}}
+ 
- Notice that if the object is invalid, it won't be saved:
+ Note: if an object is invalid, it won't be saved:
  {{{
  COUCHDB-OBJECTS> (make-and-save 'blog-post :author "Kuba" :title "Zażółć gęślą
jaźń")
  The document #<doc(NIL) :_ID "zazolc_gesla_jazn" :TITLE "Zażółć gęślą jaźń"
:AUTHOR "Kuba" :TYPE "BLOG-POST"> is invalid. Reason: attribute
@@ -198, +209 @@

  ...
  }}}
  
- = Licensing =
+ = License =
  
  
  BSD sans advertising clause.

Mime
View raw message