! Copyright (C) 2008 Alex Chapman
! See http://factorcode.org/license.txt for BSD license.
-USING: assocs couchdb kernel namespaces sequences strings tools.test ;
+USING: accessors assocs couchdb kernel namespaces sequences strings tools.test ;
IN: couchdb.tests
! You must have a CouchDB server (currently only the version from svn will
[ ] [ couch get ensure-db ] unit-test
[ 0 ] [ couch get db-info "doc_count" swap at ] unit-test
[ ] [ couch get compact-db ] unit-test
+ [ t ] [ couch get server>> next-uuid string? ] unit-test
[ ] [ H{
{ "Subject" "I like Planktion" }
{ "Tags" { "plankton" "baseball" "decisions" } }
-! Copyright (C) 2008 Alex Chapman
+! Copyright (C) 2008, 2009 Alex Chapman
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs continuations debugger hashtables http http.client io json.reader json.writer kernel make math math.parser namespaces sequences strings urls urls.encoding vectors ;
+USING: accessors arrays assocs continuations debugger hashtables http
+http.client io io.encodings.string io.encodings.utf8 json.reader
+json.writer kernel make math math.parser namespaces sequences strings
+urls urls.encoding vectors ;
IN: couchdb
! NOTE: This code only works with the latest couchdb (0.9.*), because old
: couch-http-request ( request -- data )
[ http-request ] [
dup download-failed? [
- data>> json> <couchdb-error> throw
+ response>> body>> json> <couchdb-error> throw
] [
rethrow
] if
<post-request> couch-request ;
: couch-delete ( url -- assoc )
- "DELETE" <client-request> couch-request ;
+ <delete-request> couch-request ;
: response-ok ( assoc -- assoc )
"ok" over delete-at* and t assert= ;
: uuids-url ( server -- url )
[ dup server-url % "_uuids?count=" % uuids-to-cache>> number>string % ] "" make ;
-: uuids-post ( server -- uuids )
- uuids-url f swap couch-post "uuids" swap at >vector ;
+: uuids-get ( server -- uuids )
+ uuids-url couch-get "uuids" swap at >vector ;
: get-uuids ( server -- server )
- dup uuids-post [ nip ] curry change-uuids ;
+ dup uuids-get [ nip ] curry change-uuids ;
: ensure-uuids ( server -- server )
dup uuids>> empty? [ get-uuids ] when ;
db-url "_all_docs" append couch-get ;
: <json-post-data> ( assoc -- post-data )
- >json "application/json" <post-data> swap >>data ;
+ >json utf8 encode "application/json" <post-data> swap >>data ;
! documents
: id> ( assoc -- id ) "_id" swap at ;
! construct-attachment H{ } clone
! TODO:
-! - startkey, count, descending, etc.
+! - startkey, limit, descending, etc.
! - loading specific revisions
! - views
! - attachments