zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #24507
[Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
Federico Cavalieri has proposed merging lp:~zorba-coders/zorba/feature-cloudant into lp:zorba.
Requested reviews:
Matthias Brantner (matthias-brantner)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/feature-cloudant/+merge/177111
Added cloudant module
--
https://code.launchpad.net/~zorba-coders/zorba/feature-cloudant/+merge/177111
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'modules/CMakeLists.txt'
--- modules/CMakeLists.txt 2013-07-19 17:38:21 +0000
+++ modules/CMakeLists.txt 2013-07-26 09:22:30 +0000
@@ -19,10 +19,42 @@
ADD_SUBDIRECTORY(xqxq)
ADD_SUBDIRECTORY(w3c)
ADD_SUBDIRECTORY(full-text)
-ADD_SUBDIRECTORY(http-client)
ADD_SUBDIRECTORY(json)
ADD_SUBDIRECTORY(nodes)
+
+IF(ZORBA_SUPPRESS_CURL)
+ MESSAGE(STATUS "ZORBA_SUPPRESS_CURL is true - not searching for cURL library")
+ELSE(ZORBA_SUPPRESS_CURL)
+ MESSAGE(STATUS "Looking for cURL")
+ FIND_PACKAGE(CURL)
+
+ IF(CURL_FOUND)
+ MESSAGE(STATUS "Found cURL library -- " ${CURL_LIBRARIES})
+ INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
+
+ ADD_SUBDIRECTORY(http-client)
+ ADD_SUBDIRECTORY(cloudant)
+
+ IF (WIN32) # Copy certificates for windows only
+ IF (MSVC_IDE)
+ SET(CACERT_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/../bin/${CMAKE_BUILD_TYPE}/cacert.pem")
+ ELSE (MSVC_IDE)
+ SET(CACERT_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/../bin/cacert.pem")
+ ENDIF (MSVC_IDE)
+ CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/cacert.pem" ${CACERT_DESTINATION} COPYONLY)
+ INSTALL(FILES ${CACERT_DESTINATION} DESTINATION bin)
+ ENDIF (WIN32)
+
+ ELSE(CURL_FOUND)
+ MESSAGE(STATUS "The cURL library was not found - depending modules will not be built")
+ ENDIF(CURL_FOUND)
+ENDIF(ZORBA_SUPPRESS_CURL)
+SET(ZORBA_HAVE_CURL ${CURL_FOUND} CACHE BOOL "Whether Zorba found cURL" FORCE)
+MARK_AS_ADVANCED(ZORBA_HAVE_CURL)
+
+
+
# Add external module projects - any subdirectories of a directory
# named "zorba_modules" as a sibling to the main Zorba source
# directory.
=== added directory 'modules/cloudant'
=== added file 'modules/cloudant/CMakeLists.txt'
--- modules/cloudant/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ modules/cloudant/CMakeLists.txt 2013-07-26 09:22:30 +0000
@@ -0,0 +1,17 @@
+# Copyright 2006-2012 The FLWOR Foundation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
+
+DECLARE_ZORBA_MODULE (URI "http://zorba.io/modules/cloudant" VERSION 1.0 FILE "cloudant.xq" LINK_LIBRARIES ${CURL_LIBRARIES})
\ No newline at end of file
=== added file 'modules/cloudant/cloudant.xq'
--- modules/cloudant/cloudant.xq 1970-01-01 00:00:00 +0000
+++ modules/cloudant/cloudant.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,3377 @@
+jsoniq version "1.0";
+(:
+ : Copyright 2006-2013 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+ :)
+
+(:~
+ : <p>This module provides functionality for creating, reading, updating,
+ : deleting and searching data in <a href="https://cloudant.com/">Cloudant</a>
+ : databases.</p>
+ :
+ : <p>Before issuing a request to Cloudant it is mandatory to create
+ : a new connection through one of the <code>connect</code> functions.
+ : These functions return a connection identifier which needs to be used
+ : to access data in Cloudant through the other functions.</p>
+ :
+ : <p>In these functions Cloudant databases will be identified through
+ : their names. By default, the functions will assume that the database is owned by
+ : the user for which the given connection has been created.
+ : To specify a different database owner, most functions accept an
+ : <code>$options</code> parameter that allows a <code>database-owner</code>
+ : option to specify a different database owner for a single request.
+ : Moreover, when connecting, it is possible to specify the default
+ : database owner using the <code>connect#3</code> function.</p>
+ :
+ : <p>Additional information on the Cloudant APIs can be found
+ : <a href="https://cloudant.com/for-developers/">on the Cloudant website</a>.</p>
+ :
+ : @author Federico Cavalieri
+ : @library <a href="http://curl.haxx.se/">cURL Library</a>
+ :)
+module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace http = "http://zorba.io/modules/http-client";
+
+declare namespace an = "http://www.zorba-xquery.com/annotations";
+declare namespace err = "http://www.w3.org/2005/xqt-errors";
+declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
+
+declare option ver:module-version "1.0";
+
+(:~
+ : An empty object.
+ :)
+declare variable $cloudant:empty-object as object() := {| |};
+
+(:~
+ : <p>Opens a connection to Cloudant.</p>
+ :
+ : <p>The default database owner used when calling the other database functions
+ : is the specified username.</p>
+ : <p>The function returns an opaque URI that represents the connection.
+ : This URI has to be passed to other functions of this module that require
+ : a <code>$connection</code> parameter as a first argument.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:connect("username", "password")</pre>.
+ : </p>
+ :
+ : @param $username The username used for connecting
+ : @param $password The password used for connecting
+ : @return An identifier that represents the connection to the server
+ :
+ : @error cloudant:AUTHORIZATION Authentication error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:connect($username as string, $password as string) as anyURI
+{
+ cloudant:connect($username, $password, $username)
+};
+
+(:~
+ : <p>Opens a connection to Cloudant.</p>
+ :
+ : <p>The default database owner can be specified as the last parameter</p>
+ : <p>The function returns an opaque URI that can represents the connection.
+ : This URI has to be passed to other functions of this module that require
+ : a <code>$connection</code> parameter as a first argument.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:connect("username", "password, "owner")</pre>.
+ : </p>
+ :
+ : @param $username The username used for connecting
+ : @param $password The password used for connecting
+ : @param $default-database-owner The default database owner which will be
+ : used when calling the other module functions
+ : @return An identifier that represents the connection to the server
+ :
+ : @error cloudant:AUTHORIZATION Authentication error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:connect($username as string, $password as string, $default-database-owner as string) as anyURI
+{
+ let $response:= cloudant:send-request(
+ {
+ href: cloudant:uri(fn:encode-for-uri($default-database-owner), "_session"),
+ method : "POST",
+ body:
+ {
+ "media-type": "application/x-www-form-urlencoded",
+ "content": "username="|| fn:encode-for-uri($username) || "&password=" || fn:encode-for-uri($password)
+ }
+ })
+ return
+ switch ($response.status)
+ case 200 return
+ let $session-key := fn:substring-before($response.headers."Set-Cookie",";")
+ return
+ if (empty($session-key))
+ then cloudant:error(QName("cloudant:AUTHORIZATION"),"Authorization error, malformed response", $response)
+ else cloudant:store-connection(
+ fn:encode-for-uri($username),
+ fn:encode-for-uri($default-database-owner),
+ $session-key)
+ case 403 return cloudant:error(QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Returns an array containing the names of all the user's databases.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:list-databases($connection)</pre>.
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @return An array of all the database names
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:list-databases($connection as anyURI) as array
+{
+ cloudant:list-databases($connection, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Returns an array containing the names of all the user's databases.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:list-databases($connection, {"database-owner" : "username"})</pre>.
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $options An object specifying additional request options
+ : @return An array of all the databases names
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:list-databases($connection as anyURI, $options as object) as array
+{
+ let $response:= cloudant:send-request(
+ {|
+ cloudant:request($connection,"_all_dbs", $options)
+ |})
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-array($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error",$response)
+ default return cloudant:error($response)
+};
+
+
+(:~
+ : <p>Returns information about a database.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:database-info($connection, "db")</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "update_seq": "0-g1AAAADneJzLYWBg...",
+ : "db_name": "db",
+ : "purge_seq": 0,
+ : "other": {
+ : "data_size": 0
+ : },
+ : "doc_del_count": 0,
+ : "doc_count": 0,
+ : "disk_size": 316,
+ : "disk_format_version": 5,
+ : "compact_running": false,
+ : "instance_start_time": "0"
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>compact_running: set to true if the database compaction routine is operating on this database.</li>
+ : <li>db_name: the name of the database.</li>
+ : <li>disk_format_version: the version of the physical format used for the data when it is stored on disk.</li>
+ : <li>disk_size: size in bytes of the data as stored on the disk. Views indexes are not included in the calculation.</li>
+ : <li>doc_count: a count of the documents in the specified database.</li>
+ : <li>doc_del_count: number of deleted documents.</li>
+ : <li>instance_start_time: always 0.</li>
+ : <li>purge_seq: the number of purge operations on the database.</li>
+ : <li>update_seq: the current number of updates to the database.</li>
+ : <li>other: JSON object containing a data_size field.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @return An object describing the specified database
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:database-info($connection as anyURI, $database as string) as object
+{
+ cloudant:database-info($connection, $database, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Returns information about a database.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:database-info($connection, "db", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "update_seq": "0-g1AAAADneJzLYWBg...",
+ : "db_name": "db",
+ : "purge_seq": 0,
+ : "other": {
+ : "data_size": 0
+ : },
+ : "doc_del_count": 0,
+ : "doc_count": 0,
+ : "disk_size": 316,
+ : "disk_format_version": 5,
+ : "compact_running": false,
+ : "instance_start_time": "0"
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>compact_running: set to true if the database compaction routine is operating on this database.</li>
+ : <li>db_name: the name of the database.</li>
+ : <li>disk_format_version: the version of the physical format used for the data when it is stored on disk.</li>
+ : <li>disk_size: size in bytes of the data as stored on the disk. Views indexes are not included in the calculation.</li>
+ : <li>doc_count: a count of the documents in the specified database.</li>
+ : <li>doc_del_count: number of deleted documents.</li>
+ : <li>instance_start_time: always 0.</li>
+ : <li>purge_seq: the number of purge operations on the database.</li>
+ : <li>update_seq: the current number of updates to the database.</li>
+ : <li>other: JSON object containing a data_size field.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database a database name
+ : @param $options An object specifying additional request options
+ : @return An object describing the specified database
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:database-info($connection as anyURI, $database as string, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ {|
+ cloudant:request($connection,cloudant:encode-database-name($database), $options)
+ |})
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-object($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Creates a new database.</p>
+ :
+ : <p>The database name must be composed of one or more of the following
+ : characters:
+ : <ul>
+ : <li>Lowercase characters (a-z).</li>
+ : <li>Digits (0-9).</li>
+ : <li>Any of the characters: _,$,(,),+,- and /.</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:create-database($connection, "db")</pre>.
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @return Empty sequence
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:DATABASE-EXISTS Database already exists
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:create-database($connection as anyURI, $database as string) as empty-sequence()
+{
+ let $response:= cloudant:send-request(
+ {|
+ { method : "PUT" },
+ cloudant:request($connection,cloudant:encode-database-name($database),$cloudant:empty-object)
+ |})
+ return
+ switch ($response.status)
+ case 201 return ()
+ case 403 return cloudant:error(xs:QName("cloudant:DATABASE-NAME"),"Invalid database name", $response)
+ case 412 return cloudant:error(xs:QName("cloudant:DATABASE-EXISTS"),"Database already exists", $response)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Deletes a database and all the documents and attachments contained in it.</p>
+ :
+ : <p>The database name must be composed of one or more of the following characters:
+ : <ul>
+ : <li>Lowercase characters (a-z).</li>
+ : <li>Digits (0-9).</li>
+ : <li>Any of the characters: _,$,(,),+,- and /.</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:delete-database($connection, "db")</pre>.
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @return Empty sequence
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:DATABASE-NOT-EXISTS Database does not exist
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:delete-database($connection as anyURI, $database as string) as empty-sequence()
+{
+ let $response:= cloudant:send-request(
+ {|
+ { method : "DELETE" },
+ cloudant:request($connection,cloudant:encode-database-name($database), $cloudant:empty-object)
+ |})
+ return
+ switch ($response.status)
+ case 200 return ()
+ case 404 return fn:error(xs:QName("cloudant:DATABASE-NOT-EXISTS"),"Database does not exist.")
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+
+(:~
+ : <p>Lists all the documents in a given database.</p>
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:all-documents($connection, "db")</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "total_rows":3,
+ : "offset":0,
+ : "rows":[
+ : {
+ : "id":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "key":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "value":
+ : {
+ : "rev":"2-9d5401898196997853b5ac4163857a29"
+ : }
+ : },
+ : {
+ : "id":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "key":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "value":
+ : {
+ : "rev":"2-ff7b85665c4c297838963c80ecf481a3"
+ : }
+ : },
+ : {
+ : "id":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "key":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "value":
+ : {
+ : "rev":"2-cbdef49ef3ddc127eff86350844a6108"
+ : }
+ : }]
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>offset: offset where the document list started.</li>
+ : <li>rows: array of document objects, each containing id, key and revision number.</li>
+ : <li>total_rows: number of documents in the database.</li>
+ : <li>update_seq: current update sequence database.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @return An object listing the documents in the specified database
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:all-documents($connection as anyURI, $database as string) as object
+{
+ cloudant:all-documents($connection, $database, $cloudant:empty-object)
+};
+
+
+(:~
+ : <p>Lists all the documents in a given database.</p>
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>descending: return the documents in descending by key order (boolean, default: false).</li>
+ : <li>endkey: stop returning records when the specified key is reached (string).</li>
+ : <li>endkey_docid: stop returning records when the specified document ID is reached (string).</li>
+ : <li>group: group the results using the reduce function to a group or single row (boolean, default: false).</li>
+ : <li>group_level: specify the group level to be used (numeric).</li>
+ : <li>include_docs: include the full content of the documents in the return (boolean, default: false).</li>
+ : <li>inclusive_end: specifies whether the specified end key should be included in the result (boolean, default: true).</li>
+ : <li>key: return only documents that match the specified key (string).</li>
+ : <li>limit: limit the number of the returned documents to the specified number (numeric).</li>
+ : <li>reduce: use the reduction function (boolean, default: true).</li>
+ : <li>skip: skip this number of records before starting to return the results (numeric, default: 0).</li>
+ : <li>stale: allow the results from a stale view to be used (string, allowed value: "ok").</li>
+ : <li>startkey: start returning records when the specified key is reached (string).</li>
+ : <li>startkey_docid: start returning records when the specified document ID is reached (string).</li>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:all-documents($connection, "db", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "total_rows":3,
+ : "offset":0,
+ : "rows":[
+ : {
+ : "id":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "key":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "value":
+ : {
+ : "rev":"2-9d5401898196997853b5ac4163857a29"
+ : }
+ : },
+ : {
+ : "id":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "key":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "value":
+ : {
+ : "rev":"2-ff7b85665c4c297838963c80ecf481a3"
+ : }
+ : },
+ : {
+ : "id":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "key":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "value":
+ : {
+ : "rev":"2-cbdef49ef3ddc127eff86350844a6108"
+ : }
+ : }]
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>offset: offset where the document list started.</li>
+ : <li>rows: array of document objects, each containing id, key and revision number.</li>
+ : <li>total_rows: number of documents in the database.</li>
+ : <li>update_seq: current update sequence database.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $options An object specifying additional request options
+ : @return An object listing the documents in the specified database
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:all-documents($connection as anyURI, $database as string, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/_all_docs" || cloudant:query-arguments(true, $options), $options)
+ )
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-object($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>List the specified documents in a given database.</p>
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:multiple-documents($connection, "db",
+ : ("5a049246-179f-42ad-87ac-8f080426c17c",
+ : "d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "96f898f0-f6ff-4a9b-aac4-503992f31b01"))</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "total_rows":3,
+ : "offset":0,
+ : "rows":[
+ : {
+ : "id":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "key":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "value":
+ : {
+ : "rev":"2-9d5401898196997853b5ac4163857a29"
+ : }
+ : },
+ : {
+ : "id":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "key":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "value":
+ : {
+ : "rev":"2-ff7b85665c4c297838963c80ecf481a3"
+ : }
+ : },
+ : {
+ : "id":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "key":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "value":
+ : {
+ : "rev":"2-cbdef49ef3ddc127eff86350844a6108"
+ : }
+ : }]
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>offset: offset where the document list started.</li>
+ : <li>rows: array of document objects, each containing id, key and revision number.</li>
+ : <li>total_rows: number of documents in the database.</li>
+ : <li>update_seq: current update sequence database.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $keys The keys of the documents which must be retrieved
+ : @return An object listing the specified documents in the specified database
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:multiple-documents($connection as anyURI, $database as string, $keys as string*) as object
+{
+ cloudant:multiple-documents($connection, $database, $keys, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Lists the specified documents in a given database.</p>
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>descending: return the documents in descending by key order (boolean, default: false).</li>
+ : <li>endkey: stop returning records when the specified key is reached (string).</li>
+ : <li>endkey_docid: stop returning records when the specified document ID is reached (string).</li>
+ : <li>group: group the results using the reduce function to a group or single row (boolean, default: false).</li>
+ : <li>group_level: specify the group level to be used (numeric).</li>
+ : <li>include_docs: include the full content of the documents in the return (boolean, default: false).</li>
+ : <li>inclusive_end: specifies whether the specified end key should be included in the result (boolean, default: true).</li>
+ : <li>key: return only documents that match the specified key (string).</li>
+ : <li>limit: limit the number of the returned documents to the specified number (numeric).</li>
+ : <li>reduce: use the reduction function (boolean, default: true).</li>
+ : <li>skip: skip this number of records before starting to return the results (numeric, default: 0).</li>
+ : <li>stale: allow the results from a stale view to be used (string, allowed value: "ok").</li>
+ : <li>startkey: start returning records when the specified key is reached (string).</li>
+ : <li>startkey_docid: start returning records when the specified document ID is reached (string).</li>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:multiple-documents($connection, "db",
+ : ("5a049246-179f-42ad-87ac-8f080426c17c",
+ : "d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "96f898f0-f6ff-4a9b-aac4-503992f31b01"),
+ : {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "total_rows":3,
+ : "offset":0,
+ : "rows":[
+ : {
+ : "id":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "key":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "value":
+ : {
+ : "rev":"2-9d5401898196997853b5ac4163857a29"
+ : }
+ : },
+ : {
+ : "id":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "key":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "value":
+ : {
+ : "rev":"2-ff7b85665c4c297838963c80ecf481a3"
+ : }
+ : },
+ : {
+ : "id":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "key":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "value":
+ : {
+ : "rev":"2-cbdef49ef3ddc127eff86350844a6108"
+ : }
+ : }]
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>offset: offset where the document list started.</li>
+ : <li>rows: array of document objects, each containing id, key and revision number.</li>
+ : <li>total_rows: number of documents in the database.</li>
+ : <li>update_seq: current update sequence database.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $keys The keys of the documents which must be retrieved
+ : @param $options An object specifying additional request options
+ : @return An object listing the specified documents in the specified database
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:multiple-documents($connection as anyURI, $database as string, $keys as string*, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ {|
+ {
+ method : "POST",
+ body:
+ {
+ "media-type": "application/json",
+ "content": fn:serialize(
+ {
+ keys: [$keys]
+ })
+ }
+ },
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/_all_docs"|| cloudant:query-arguments(true, $options), $options)
+ |})
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-object($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Creates, updates or deletes multiple documents with a single request.</p>
+ :
+ : <p>When creating new documents the document ID is optional. For updating
+ : existing documents, you must provide the document ID, revision information,
+ : and new document values. To delete existing documents, you must provide the
+ : document ID, revision information and add a field <code>_deleted</code> having
+ : value <code>true</code>.
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:bulk-crud($connection, "db",
+ : (
+ : {
+ : "name":"Nicholas",
+ : "age":45,
+ : "gender":"male",
+ : },
+ : {
+ : "name":"Taylor",
+ : "age":50,
+ : "gender":"male",
+ : "_id":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : },
+ : {
+ : "name":"Owen",
+ : "age":51,
+ : "gender":"male",
+ : "_id":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "_rev":"2-f29c836d0bedc4b4b95cfaa6d99e95df",
+ : },
+ : {
+ : "_id":"b675e932-9bb6-4fc9-b889-50238ac3512b",
+ : "_rev":"2-abd3942fdab3515bfed224abed2451feb",
+ : "_deleted": true
+ : }
+ : ))
+ : </pre>
+ : requires to insert the first document with a system-generated identifier, to insert the second
+ : one with a user-specified identifier, to update the third one and, finally,to delete the last one.
+ : </p>
+ :
+ : <p>
+ : The JSON returned by the_bulk_docs operation consists of an array
+ : of JSON structures, one for each submitted document.
+ : The returned JSON structure should be examined to ensure that all of
+ : the documents submitted in the original request were successfully added
+ : to the database. When no errors are raised, the revision of the new
+ : document is reported for all documents.
+ : </p>
+ :
+ : <p>
+ : <pre>
+ : [{
+ : "id":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "rev":"2-ff7b85665c4c297838963c80ecf481a3"
+ : },
+ : {
+ : "id":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "rev":"2-9d5401898196997853b5ac4163857a29"
+ : },
+ : {
+ : "id":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "rev":"2-cbdef49ef3ddc127eff86350844a6108"
+ : },
+ : {
+ : "id": "b675e932-9bb6-4fc9-b889-50238ac3512b",
+ : "rev":"2-12356bafb1232167befabb32127823943d"
+ : }]
+ : </pre>
+ : </p>
+ :
+ : <p>Cloudant will only guarantee that some of the documents will be
+ : saved when you send the request. The response will contain the list of
+ : documents successfully inserted or updated during the process.
+ : In the event of a crash, some of the documents may have been successfully
+ : saved, and some will have been lost.
+ : The response structure will indicate whether the document was updated by
+ : supplying the <code>rev</code> parameter indicating a new document revision
+ : was created. If the update failed, then you will get an error of type
+ : <code>conflict</code>.</p>
+ :
+ : <p>For example:
+ : <pre>
+ : [
+ : {
+ : "id":"FishStew",
+ : "error":"conflict",
+ : "reason":"Document update conflict."
+ : },
+ : {
+ : "id":"LambStew",
+ : "error":"conflict",
+ : "reason":"Document update conflict."
+ : },
+ : {
+ : "id":"7f7638c86173eb440b8890839ff35433",
+ : "error":"conflict",
+ : "reason":"Document update conflict."
+ : }
+ : ]
+ : </pre>
+ : In this case no new revision has been created and you will need to submit
+ : the document update with the correct revision tag, to update the document.
+ : </p>
+ : <p>The exact structure of each document in the returned array is:
+ : <ul>
+ : <li>id: the document ID</li>
+ : <li>rev: the new document revision, if a new revision was created</li>
+ : <li>error: the error type, if an error was raised</li>
+ : <li>reason: a description of the raised error, if an error was raised</li>
+ : </ul>
+ : </p>
+ :
+ : <p>The error type can either be conflict or forbidden. The first type means that
+ : the document as submitted is in conflict. The new revision has not been created
+ : and you will need to re-submit the document to the database. Entries with forbidden
+ : error type indicate that the validation routine applied to the document during submission
+ : has returned an error.</p>
+ :
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $documents An sequence of documents
+ : @return An object describing the performed operations
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:bulk-crud($connection as anyURI, $database as string, $documents as object*) as array
+{
+ cloudant:bulk-crud($connection, $database, $documents, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Creates, updates or deletes multiple documents with a single request.</p>
+ :
+ : <p>When creating new documents the document ID is optional. For updating
+ : existing documents, you must provide the document ID, revision information,
+ : and new document values. To delete existing documents, you must provide the
+ : document ID, revision information and add a field <code>_deleted</code> having
+ : value <code>true</code>.
+ : </p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>all_or_nothing: sets the database commit mode to use all-or-nothing semantics (boolean, default: false).</li>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:bulk-crud($connection, "db",
+ : (
+ : {
+ : "name":"Nicholas",
+ : "age":45,
+ : "gender":"male",
+ : },
+ : {
+ : "name":"Taylor",
+ : "age":50,
+ : "gender":"male",
+ : "_id":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : },
+ : {
+ : "name":"Owen",
+ : "age":51,
+ : "gender":"male",
+ : "_id":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "_rev":"2-f29c836d0bedc4b4b95cfaa6d99e95df",
+ : },
+ : {
+ : "_id":"b675e932-9bb6-4fc9-b889-50238ac3512b",
+ : "_rev":"2-abd3942fdab3515bfed224abed2451feb",
+ : "_deleted": true
+ : }
+ : ),{"database-owner": "username"})
+ : </pre>
+ : requires to insert the first document with a system-generated identifier, to insert the second
+ : one with a user-specified identifier, to update the third one and, finally, to delete the last one.
+ : </p>
+ :
+ : <p>
+ : The JSON returned by the_bulk_docs operation consists of an array
+ : of JSON structures, one for each document in the original submission.
+ : The returned JSON structure should be examined to ensure that all of
+ : the documents submitted in the original request were successfully added
+ : to the database. When no errors are raised, the revision of the new
+ : document is reported for all documents.
+ : </p>
+ :
+ : <p>
+ : <pre>
+ : [{
+ : "id":"96f898f0-f6ff-4a9b-aac4-503992f31b01",
+ : "rev":"2-ff7b85665c4c297838963c80ecf481a3"
+ : },
+ : {
+ : "id":"5a049246-179f-42ad-87ac-8f080426c17c",
+ : "rev":"2-9d5401898196997853b5ac4163857a29"
+ : },
+ : {
+ : "id":"d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
+ : "rev":"2-cbdef49ef3ddc127eff86350844a6108"
+ : },
+ : {
+ : "id": "b675e932-9bb6-4fc9-b889-50238ac3512b",
+ : "rev":"2-12356bafb1232167befabb32127823943d"
+ : }]
+ : </pre>
+ : </p>
+ :
+ : <p>Cloudant will only guarantee that some of the documents will be
+ : saved when you send the request. The response will contain the list of
+ : documents successfully inserted or updated during the process.
+ : In the event of a crash, some of the documents may have been successfully
+ : saved, and some will have been lost.
+ : The response structure will indicate whether the document was updated by
+ : supplying the <code>rev</code> parameter indicating a new document revision
+ : was created. If the update failed, then you will get an error of type
+ : <code>conflict</code>.</p>
+ :
+ : <p>For example:
+ : <pre>
+ : [
+ : {
+ : "id":"FishStew",
+ : "error":"conflict",
+ : "reason":"Document update conflict."
+ : },
+ : {
+ : "id":"LambStew",
+ : "error":"conflict",
+ : "reason":"Document update conflict."
+ : },
+ : {
+ : "id":"7f7638c86173eb440b8890839ff35433",
+ : "error":"conflict",
+ : "reason":"Document update conflict."
+ : }
+ : ]
+ : </pre>
+ : In this case no new revision has been created and you will need to submit
+ : the document update with the correct revision tag, to update the document.
+ : </p>
+ : <p>The exact structure of each document in the returned array is:
+ : <ul>
+ : <li>id: the document ID</li>
+ : <li>rev: the new document revision, if a new revision was created</li>
+ : <li>error: the error type, if an error was raised</li>
+ : <li>reason: a description of the raised error, if an error was raised</li>
+ : </ul>
+ : </p>
+ :
+ : <p>The error type can either be conflict or forbidden. The first type means that
+ : the document as submitted is in conflict. The new revision has not been created
+ : and you will need to re-submit the document to the database. Entries with forbidden
+ : error type indicate that the validation routine applied to the document during submission
+ : has returned an error.</p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $documents An sequence of documents
+ : @param $options An object specifying additional request options
+ : @return An object describing the performed operations
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:bulk-crud($connection as anyURI, $database as string, $documents as object*, $options as object) as array
+{
+ let $response:= cloudant:send-request(
+ {|
+ {
+ method : "POST",
+ body:
+ {
+ "media-type": "application/json",
+ "content": fn:serialize(
+ {
+ docs: [$documents]
+ })
+ }
+ },
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/_bulk_docs", $options)
+ |})
+ return
+ switch ($response.status)
+ case 201 return cloudant:parse-array($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Commits any recent changes to the specified database to disk.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:commit-changes($connection, "db")</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "ok" : true,
+ : "instance_start_time" : "0"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @return An object reporting the instance start time
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NOT-EXISTS The specified database does not exists
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:commit-changes($connection as anyURI, $database as string) as object
+{
+ cloudant:commit-changes($connection, $database, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Commits any recent changes to the specified database to disk.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:commit-changes($connection, "db", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "ok" : true,
+ : "instance_start_time" : "0"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $options An object specifying additional request options
+ : @return An object reporting the instance start time
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NOT-EXISTS The specified database does not exists
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:commit-changes($connection as anyURI, $database as string, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ {|
+ {method: "POST"},
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/_ensure_full_commit", $options)
+ |})
+ return
+ switch ($response.status)
+ case 201 return cloudant:parse-object($response.body.content)
+ case 202 return cloudant:parse-object($response.body.content)
+ case 404 return fn:error(xs:QName("cloudant:DATABASE-NOT-EXISTS"),"Database does not exist.")
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+
+(:~
+ : <p>Creates a new document in the specified database.</p>
+ :
+ : <p>Creates a new document in the specified database,
+ : using the supplied JSON document structure. If the JSON
+ : structure includes the _id field, then the document will
+ : be created with the specified document ID. If the _id
+ : field is not specified, a new unique ID will be generated.</p>
+ :
+ : <p>You can include one or more attachments with a given document
+ : by incorporating the attachment information within the JSON of
+ : the document. This provides a simpler alternative to loading
+ : documents with attachments than making a separate call.
+ : To do so add you can add the <code>_attachments</code> object
+ : field to the document. It can have one ore more fields, each
+ : defining a different attachment.
+ : The name of the field is the name of the attachment.
+ : Its value is an object containing the following fields:
+ : <ul>
+ : <li>content_type: MIME Content type string</li>
+ : <li>data: File attachment content, Base64 encoded</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:create-document($connection, "db",
+ : {
+ : "_id" : "FishStew",
+ : "servings" : 4,
+ : "subtitle" : "Delicious with fresh bread",
+ : "title" : "Fish Stew"
+ : "_attachments" : {
+ : "styling.css" : {
+ : "content-type" : "text/css",
+ : "data" : "cCB7IGZvbnQtc2l6ZTogMTJwdDsgfQo="
+ : }
+ : }
+ : })
+ : </pre>
+ : creates a document with an attachment named <code>styling.css</code>.
+ : </p>
+ :
+ : <h4>Creating a design document</h4>
+ :
+ : <p>To create a design document the <code>_id</code> field must be present and must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example, the following expression creates a design document
+ : <pre>cloudant:create-document($connection, "db",
+ : {
+ : "_id": "_design/DesDocID",
+ : "views": {
+ : "view1": {
+ : "map":"function(doc){emit(doc.field, 1)}",
+ : "reduce": "function(key, value, rereduce){return sum(values)}"
+ : }
+ : },
+ : "indexes": {
+ : "mysearch" : {
+ : "analyzer": {"name": "portuguese", "stopwords":["foo", "bar, "baz"]},
+ : "index": "function(doc){ ... }"
+ : },
+ : }
+ : }, {"database-owner": "username"})
+ : </pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ :
+ : <p>The returned JSON object will report the new document revision
+ : and has the following form:
+ : <pre>
+ : {
+ : "id":"64575eef70ab90a2b8d55fc09e00440d",
+ : "ok":true,
+ : "rev":"1-9c65296036141e575d32ba9c034dd3ee"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document A document
+ : @return An object which contains the document id and revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:DOCUMENT-CONFLICT Document creation conflict
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:create-document($connection as anyURI, $database as string, $document as object) as object()
+{
+ cloudant:create-document($connection,$database,$document,$cloudant:empty-object)
+};
+
+(:~
+ : <p>Creates a new document in the specified database</p>
+ :
+ : <p>Creates a new document in the specified database,
+ : using the supplied JSON document structure. If the JSON
+ : structure includes the _id field, then the document will
+ : be created with the specified document ID. If the _id
+ : field is not specified, a new unique ID will be generated.</p>
+ :
+ : <p>You can include one or more attachments with a given document
+ : by incorporating the attachment information within the JSON of
+ : the document. This provides a simpler alternative to loading
+ : documents with attachments than making a separate call.
+ : To do so add you can add the <code>_attachments</code> object
+ : field to the document. It can have one ore more fields, each
+ : defining a different attachment.
+ : The name of the field is the name of the attachment.
+ : Its value is an object containing the following fields:
+ : <ul>
+ : <li>content_type: MIME Content type string</li>
+ : <li>data: File attachment content, Base64 encoded</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:create-document($connection, "db",
+ : {
+ : "_id" : "FishStew",
+ : "servings" : 4,
+ : "subtitle" : "Delicious with fresh bread",
+ : "title" : "Fish Stew"
+ : "_attachments" : {
+ : "styling.css" : {
+ : "content-type" : "text/css",
+ : "data" : "cCB7IGZvbnQtc2l6ZTogMTJwdDsgfQo="
+ : }
+ : }
+ : }, {"database-owner": "username"})
+ : </pre>
+ : creates a document with an attachment named <code>styling.css</code>.
+ : </p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>batch: requires batch mode for insertions (string, allowed value: "ok")</li>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>You can write documents to the database at a higher rate
+ : by using the batch option. This collects document writes
+ : together in memory (on a user-by-user basis) before they are
+ : committed to disk. This increases the risk of the documents
+ : not being stored in the event of a failure, since the documents
+ : are not written to disk immediately.</p>
+ :
+ : <h4>Creating a design document</h4>
+ :
+ : <p>To create a design document the <code>_id</code> field must be present and must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example, the following expression creates a design document
+ : <pre>cloudant:create-document($connection, "db",
+ : {
+ : "_id": "_design/DesDocID",
+ : "views": {
+ : "view1": {
+ : "map":"function(doc){emit(doc.field, 1)}",
+ : "reduce": "function(key, value, rereduce){return sum(values)}"
+ : }
+ : },
+ : "indexes": {
+ : "mysearch" : {
+ : "analyzer": {"name": "portuguese", "stopwords":["foo", "bar, "baz"]},
+ : "index": "function(doc){ ... }"
+ : },
+ : }
+ : }, {"database-owner": "username"})
+ : </pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ :
+ : <p>The returned JSON object will report the new document revision
+ : and has the following form:
+ : <pre>
+ : {
+ : "id":"64575eef70ab90a2b8d55fc09e00440d",
+ : "ok":true,
+ : "rev":"1-9c65296036141e575d32ba9c034dd3ee"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document A document
+ : @param $options An object specifying additional request options
+ : @return An object which contains the document id and revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:DOCUMENT-CONFLICT Document creation conflict
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:create-document($connection as anyURI, $database as string, $document as object, $options as object) as object()
+{
+ let $response:= cloudant:send-request(
+ {|
+ {
+ method : "POST",
+ body:
+ {
+ "media-type": "application/json",
+ "content": fn:serialize($document)
+ }
+ },
+ cloudant:request($connection,cloudant:encode-database-name($database) || cloudant:query-arguments(true, $options),$options)
+ |})
+ return
+ switch ($response.status)
+ case 201 return cloudant:parse-object($response.body.content)
+ case 202 return cloudant:parse-object($response.body.content)
+ case 409 return cloudant:error(xs:QName("cloudant:DOCUMENT-CONFLICT"),"Document creation conflict", $response)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Retrieves a document from the specified database.</p>
+ :
+ : <p>The latest revision of the document will be returned.</p>
+ :
+ : <p>If the document includes attachments, then the
+ : returned structure will contain a summary of the
+ : attachments associated with the document, but not the
+ : attachment data itself.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document($connection, "db", "DocID")</pre>.
+ : </p>
+ :
+ : <p>The returned JSON object will contain the document
+ : and has the following format:
+ : <pre>
+ : {
+ : "_id": "DocID",
+ : "_rev": "2-f29c836d0bedc4b4b95cfaa6d99e95df",
+ : "name": "Anna",
+ : "age": 89,
+ : "gender": "female",
+ : "_attachments": {
+ : "my attachment": {
+ : "content_type": "application/json; charset=UTF-8",
+ : "revpos": 2,
+ : "digest": "md5-37IZysiyWLRWx31J/1WQHw==",
+ : "length": 12,
+ : "stub": true
+ : }
+ : }
+ : }
+ : </pre>
+ : </p>
+ : <p>
+ : The meaning of the fields in the returned object is the following:
+ : <ul>
+ : <li>_id: document ID</li>
+ : <li>_rev: document revision</li>
+ : <li>attachments: document attachments (optional), each field denotes the name
+ : of a different attachment
+ : <ul>
+ : <li>content_type: attachment MIME Content type string</li>
+ : <li>length: attachment length in bytes</li>
+ : <li>revpos: revision where this attachment exists</li>
+ : <li>digest: MD5 checksum of the attachment</li>
+ : <li>stub: indicates whether the attachment is a stub</li>
+ : </ul>
+ : </li>
+ : </ul>
+ : </p>
+ :
+ : <h4>Retrieving a design document from the specified database</h4>
+ :
+ : <p>To retrieve a design document the document id must start with
+ : <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document($connection, "db", "_design/DesDocID")</pre>.
+ : </p>
+ :
+ : <p>A JSON object with the following format is returned:
+ : <pre>
+ : {
+ : "_id": "_design/DesDocID",
+ : "views": {
+ : "view1": {
+ : "map":"function(doc){emit(doc.field, 1)}",
+ : "reduce": "function(key, value, rereduce){return sum(values)}"
+ : }
+ : },
+ : "indexes": {
+ : "mysearch" : {
+ : "analyzer": {"name": "portuguese", "stopwords":["foo", "bar, "baz"]},
+ : "index": "function(doc){ ... }"
+ : },
+ : }
+ : }
+ : </pre>
+ : </p>
+ :
+ : <p>
+ : The meaning of the fields in the returned object is the following:
+ : <ul>
+ : <li>_id: document ID</li>
+ : <li>_rev: document revision</li>
+ : <li>views: object defining the views. Each field defines a different view.
+ : The field name is the name of the view and has the following content:
+ : <ul>
+ : <li>map: view map function</li>
+ : <li>reduce: view reduce function (optional)</li>
+ : </ul>
+ : </li>
+ : <li>indexes: object defining the view indexes. Each field defines a different index.
+ : The field name is the name of the index and has the following content:
+ : <ul>
+ : <li>analyzer: Name of the analyzer to be used or an object with the following fields:
+ : <ul>
+ : <li>name: Name of the analyzer</li>
+ : <li>stopwords: An array of stop words. Stop words are words that should not be indexed.</li>
+ : </ul>
+ : </li>
+ : <li>index: Function that handles the indexing</li>
+ : </ul>
+ : </li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @return The specified document
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:DOCUMENT-CONFLICT The specified document or revision cannot be found
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:document($connection as anyURI, $database as string, $document-id as string) as object()
+{
+ cloudant:document($connection, $database, $document-id, $cloudant:empty-object)
+};
+
+
+(:~
+ : <p>Retrieves a document from the specified database</p>
+ :
+ : <p>Unless you request a specific revision, the latest
+ : revision of the document will always be returned.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>conflict: returns the conflict tree for the document (boolean)</li>
+ : <li>rev: specifies the revision to return (string)</li>
+ : <li>revs: return a list of the revisions for the document (boolean)</li>
+ : <li>revs_info: return a list of detailed revision information for the document (boolean, allowed value: true)</li>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>If the document includes attachments, then the
+ : returned structure will contain a summary of the
+ : attachments associated with the document, but not the
+ : attachment data itself.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document($connection, "db", "DocID", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <p>The returned JSON object will contain the document
+ : and has the following format:
+ : <pre>
+ : {
+ : "_id": "DocID",
+ : "_rev": "2-f29c836d0bedc4b4b95cfaa6d99e95df",
+ : "name": "Anna",
+ : "age": 89,
+ : "gender": "female",
+ : "_attachments": {
+ : "my attachment": {
+ : "content_type": "application/json; charset=UTF-8",
+ : "revpos": 2,
+ : "digest": "md5-37IZysiyWLRWx31J/1WQHw==",
+ : "length": 12,
+ : "stub": true
+ : }
+ : }
+ : }
+ : </pre>
+ : </p>
+ : <p>
+ : The meaning of the fields in the returned object is the following:
+ : <ul>
+ : <li>_id: document ID</li>
+ : <li>_rev: document revision</li>
+ : <li>attachments: document attachments (optional), each field denotes the name
+ : of a different attachment:
+ : <ul>
+ : <li>content_type: attachment MIME Content type string</li>
+ : <li>length: attachment length in bytes</li>
+ : <li>revpos: revision where this attachment exists</li>
+ : <li>digest: MD5 checksum of the attachment</li>
+ : <li>stub: indicates whether the attachment is a stub</li>
+ : </ul>
+ : </li>
+ : </ul>
+ : </p>
+ :
+ : <h4>Retrieving a design document from the specified database</h4>
+ :
+ : <p>To retrieve a design document the document id must start with
+ : <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document($connection, "db", "_design/DesDocID", {"database-owner": "username"})</pre>.
+ : </p>
+ : <p>A JSON object with the following format is returned:
+ : <pre>
+ : {
+ : "_id": "_design/DesDocID",
+ : "_rev": "2-f29c836d0bedc4b4b95cfaa6d99e95df",
+ : "views": {
+ : "view1": {
+ : "map":"function(doc){emit(doc.field, 1)}",
+ : "reduce": "function(key, value, rereduce){return sum(values)}"
+ : }
+ : },
+ : "indexes": {
+ : "mysearch" : {
+ : "analyzer": {"name": "portuguese", "stopwords":["foo", "bar, "baz"]},
+ : "index": "function(doc){ ... }"
+ : },
+ : }
+ : }
+ : </pre>
+ : </p>
+ :
+ : <p>
+ : The meaning of the fields in the returned object is the following:
+ : <ul>
+ : <li>_id: document ID</li>
+ : <li>_rev: document revision</li>
+ : <li>views: object defining the views. Each field defines a different view.
+ : The field name is the name of the view and has the following content:
+ : <ul>
+ : <li>map: view map function</li>
+ : <li>reduce: view reduce function (optional)</li>
+ : </ul>
+ : </li>
+ : <li>indexes: object defining the view indexes. Each field defines a different index.
+ : The field name is the name of the index and has the following content:
+ : <ul>
+ : <li>analyzer: Name of the analyzer to be used or an object with the following fields:
+ : <ul>
+ : <li>name: Name of the analyzer</li>
+ : <li>stopwords: An array of stop words. Stop words are words that should not be indexed.</li>
+ : </ul>
+ : </li>
+ : <li>index: Function that handles the indexing</li>
+ : </ul>
+ : </li>
+ : </ul>
+ : </p>
+ :
+ : <h4>Getting a List of Revisions</h4>
+ : <p>You can obtain a list of the revisions for a given document
+ : by the revs option.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document($connection, "db", "DocID", {"revs": true})</pre>.
+ : </p>
+ :
+ : <p>The returned JSON object includes the original document and
+ : a <code>_revisions</code> structure that includes the revision
+ : information:
+ : <pre>
+ : {
+ : "servings":4,
+ : "subtitle":"Delicious with a green salad",
+ : "_id":"FishStew",
+ : "title":"Irish Fish Stew",
+ : "_revisions":
+ : {
+ : "ids": [
+ : "a1a9b39ee3cc39181b796a69cb48521c",
+ : "7c4740b4dcf26683e941d6641c00c39d",
+ : "9c65296036141e575d32ba9c034dd3ee"
+ : ],
+ : "start":3
+ : },
+ : "_rev":"3-a1a9b39ee3cc39181b796a69cb48521c"
+ : }
+ : </pre>
+ : </p>
+ : <p>The meaning of the additional fields is the following:
+ : <ul>
+ : <li>_revisions: document revisions</li>
+ : <li>_ids: array of valid revision IDs, in reverse order (latest first)</li>
+ : <li>start: prefix number for the latest revision</li>
+ : </ul>
+ : </p>
+ :
+ : <h4>Obtaining an Extended Revision History</h4>
+ : <p>You can get additional information about the revisions for a given document
+ : with the <code>revs_info</code> option.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document($connection, "db", "DocID", {"revs_info": true})</pre>.
+ : </p>
+ :
+ : <p>This returns extended revision information, including the availability and status
+ : of each revision:
+ : <pre>
+ : {
+ : "servings":4,
+ : "subtitle":"Delicious with a green salad",
+ : "_id":"FishStew",
+ : "_revs_info":[
+ : {
+ : "status":"available",
+ : "rev":"3-a1a9b39ee3cc39181b796a69cb48521c"
+ : },
+ : {
+ : "status":"available",
+ : "rev":"2-7c4740b4dcf26683e941d6641c00c39d"
+ : },
+ : {
+ : "status":"available",
+ : "rev":"1-9c65296036141e575d32ba9c034dd3ee"
+ : }
+ : ],
+ : "title":"Irish Fish Stew",
+ : "_rev":"3-a1a9b39ee3cc39181b796a69cb48521c"
+ : }
+ : </pre>
+ : </p>
+ :
+ : <p>The meaning of the additional fields is the following:
+ : <ul>
+ : <li>_revs_info: document extended revision info</li>
+ : <li>rev: revision ID</li>
+ : <li>status: revision status</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $options An object specifying additional request options
+ : @return The specified document
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:DOCUMENT-CONFLICT The specified document or revision cannot be found
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:document($connection as anyURI, $database as string, $document-id as string, $options as object) as object()
+{
+ let $response:= cloudant:send-request(
+ {|
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/" || cloudant:prepare-document-id($document-id) ||
+ cloudant:query-arguments(true, $options), $options)
+ |})
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-object($response.body.content)
+ case 400 return fn:error(xs:QName("cloudant:DOCUMENT-CONFLICT"),"The format of the request or revision is invalid.")
+ case 404 return fn:error(xs:QName("cloudant:DOCUMENT-CONFLICT"),"The specified document or revision cannot be found.")
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Returns the latest revision and size for a given document.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document-info($connection, "db", "DocID")</pre>.
+ : </p>
+ :
+ : <p>The format of the returned object is the following and contains
+ : the document id, latest revision and size.
+ : <pre>
+ : {
+ : "ok": true,
+ : "id": "DocID",
+ : "rev": "1-764b9b11845fd0b73cfa0e61acc74ecf",
+ : "size": 500
+ : }
+ : </pre>
+ : </p>
+ :
+ : <h4>Returning the latest revision and size for a given design document</h4>
+ :
+ : <p>To return the latest revision and size of a design document the document id must start with
+ : <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document-info($connection, "db", "_design/DesDocID")</pre>.
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @return An object specifying the document id, revision and size
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DOCUMENT-CONFLICT The specified document or revision cannot be found
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:document-info($connection as anyURI, $database as string, $document-id as string) as object()
+{
+ cloudant:document-info($connection, $database, $document-id, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Returns the latest revision and size for a given document.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document-info($connection, "db", "DocID", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <p>The format of the returned object is the following and contains
+ : the document id, latest revision and size.
+ : <pre>
+ : {
+ : "ok": true,
+ : "id": "DocID",
+ : "rev": "1-764b9b11845fd0b73cfa0e61acc74ecf",
+ : "size": 500
+ : }
+ : </pre>
+ : </p>
+ :
+ : <h4>Returning the latest revision and size for a given design document</h4>
+ :
+ : <p>To return the latest revision and size of a design document the document id must start with
+ : <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:document-info($connection, "db", "_design/DesDocID", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $options An object specifying additional request options
+ : @return An object specifying the document id, revision and size
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DOCUMENT-CONFLICT The specified document or revision cannot be found
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:document-info($connection as anyURI, $database as string, $document-id as string, $options as object) as object()
+{
+ let $response:= cloudant:send-request(
+ {|
+ {method: "HEAD"},
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/" || cloudant:prepare-document-id($document-id), $options)
+ |})
+ return
+ switch ($response.status)
+ case 200 return
+ {
+ "ok": true,
+ "id": $document-id,
+ "rev": fn:replace($response.headers.Etag,"\"",""),
+ "size": $response.headers("Content-Length")
+ }
+ case 404 return fn:error(xs:QName("cloudant:DOCUMENT-CONFLICT"),"The specified document or revision cannot be found.")
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+
+(:~
+ : <p>Creates or updates a document.</p>
+ :
+ : <p>When creating a new document, the <code>_id</code> field must
+ : be specified.</p>
+ : <p>For example,
+ : <pre>cloudant:create-or-update-document($connection, "db",
+ : {
+ : "name":"Hannah",
+ : "age":120,
+ : "gender":"female",
+ : "_id":"DocID"
+ : })</pre>.
+ : </p>
+ :
+ : <p>When updating a document, the <code>_id</code> and the
+ : <code>_rev</code> field, which contains the last document revision,
+ : must be specified.</p>
+ : <p>For example,
+ : <pre>cloudant:create-or-update-document($connection, "db",
+ : {
+ : "name":"Hannah",
+ : "age":40,
+ : "gender":"female",
+ : "_id":"DocID",
+ : "_rev":"1-764b9b11845fd0b73cfa0e61acc74ecf"
+ : })</pre>.
+ : </p>
+ :
+ : <h4>Creating or updating a design document</h4>
+ :
+ : <p>To create or update a design document the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example, the following expression creates a design document
+ : <pre>cloudant:create-or-update-document($connection, "db",
+ : {
+ : "_id": "_design/DesDocID",
+ : "views": {
+ : "view1": {
+ : "map":"function(doc){emit(doc.field, 1)}",
+ : "reduce": "function(key, value, rereduce){return sum(values)}"
+ : }
+ : },
+ : "indexes": {
+ : "mysearch" : {
+ : "analyzer": {"name": "portuguese", "stopwords":["foo", "bar, "baz"]},
+ : "index": "function(doc){ ... }"
+ : },
+ : }
+ : })
+ : </pre>.
+ : </p>
+ :
+ : <p>For example, the following expression updates a design document
+ : <pre>cloudant:create-or-update-document($connection, "db",
+ : {
+ : "_id": "_design/DesDocID",
+ : "_rev": "2-f29c836d0bedc4b4b95cfaa6d99e95df",
+ : "views": {
+ : "view1": {
+ : "map":"function(doc){emit(doc.field, 1)}",
+ : "reduce": "function(key, value, rereduce){return sum(values)}"
+ : }
+ : },
+ : "indexes": {
+ : "mysearch" : {
+ : "analyzer": {"name": "portuguese", "stopwords":["foo", "bar, "baz"]},
+ : "index": "function(doc){ ... }"
+ : },
+ : }
+ : })
+ : </pre>.</p>
+ :
+ : <p>
+ : The meaning of the fields in the design document is the following:
+ : <ul>
+ : <li>_id: document ID</li>
+ : <li>_rev: document revision</li>
+ : <li>views: object defining the views. Each field defines a different view.
+ : The field name is the name of the view and has the following content:
+ : <ul>
+ : <li>map: view map function</li>
+ : <li>reduce: view reduce function (optional)</li>
+ : </ul>
+ : </li>
+ : <li>indexes: object defining the view indexes. Each field defines a different index.
+ : The field name is the name of the index and has the following content:
+ : <ul>
+ : <li>analyzer: Name of the analyzer to be used or an object with the following fields:
+ : <ul>
+ : <li>name: Name of the analyzer</li>
+ : <li>stopwords: An array of stop words. Stop words are words that should not be indexed.</li>
+ : </ul>
+ : </li>
+ : <li>index: Function that handles the indexing</li>
+ : </ul>
+ : </li>
+ : </ul>
+ : </p>
+ :
+ : <h4>Return value</h4>
+ :
+ : <p>The format of the returned object is the following and contains
+ : the document id and revision.
+ : <pre>
+ : {
+ : "ok":true,
+ : "id":"DocID",
+ : "rev":"1-764b9b11845fd0b73cfa0e61acc74ecf"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document A document
+ : @return An object which specifies the document id and its new revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:DOCUMENT-MALFORMED Malformed document object
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:create-or-update-document($connection as anyURI, $database as string, $document as object) as object
+{
+ cloudant:create-or-update-document($connection, $database, $document, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Creates or updates a document.</p>
+ :
+ : <p>When creating a new document, the <code>_id</code> field must
+ : be specified.</p>
+ : <p>For example,
+ : <pre>cloudant:create-or-update-document($connection, "db", "DocID",
+ : {
+ : "name":"Hannah",
+ : "age":120,
+ : "gender":"female",
+ : "_id":"DocID"
+ : }, {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <p>When updating a document, the <code>_id</code> and the
+ : <code>_rev</code> field, which contains the last document revision,
+ : must be specified.</p>
+ : <p>For example,
+ : <pre>cloudant:create-or-update-document($connection, "db", "DocID",
+ : {
+ : "name":"Hannah",
+ : "age":40,
+ : "gender":"female",
+ : "_id":"DocID",
+ : "_rev":"1-764b9b11845fd0b73cfa0e61acc74ecf"
+ : }, {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <h4>Creating or updating a design document</h4>
+ :
+ : <p>To create or update a design document the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example, the following expression creates a design document
+ : <pre>cloudant:create-or-update-document($connection, "db",
+ : {
+ : "_id": "_design/DesDocID",
+ : "views": {
+ : "view1": {
+ : "map":"function(doc){emit(doc.field, 1)}",
+ : "reduce": "function(key, value, rereduce){return sum(values)}"
+ : }
+ : },
+ : "indexes": {
+ : "mysearch" : {
+ : "analyzer": {"name": "portuguese", "stopwords":["foo", "bar, "baz"]},
+ : "index": "function(doc){ ... }"
+ : },
+ : }
+ : }, {"database-owner": "username"})
+ : </pre>.
+ : </p>
+ : <pre>cloudant:create-or-update-document($connection, "db",
+ : {
+ : "_id": "_design/DesDocID",
+ : "_rev": "2-f29c836d0bedc4b4b95cfaa6d99e95df",
+ : "views": {
+ : "view1": {
+ : "map":"function(doc){emit(doc.field, 1)}",
+ : "reduce": "function(key, value, rereduce){return sum(values)}"
+ : }
+ : },
+ : "indexes": {
+ : "mysearch" : {
+ : "analyzer": {"name": "portuguese", "stopwords":["foo", "bar, "baz"]},
+ : "index": "function(doc){ ... }"
+ : },
+ : }
+ : }, {"database-owner": "username"})
+ : </pre>.
+ :
+ : <p>
+ : The meaning of the fields in the design document is the following:
+ : <ul>
+ : <li>_id: document ID</li>
+ : <li>_rev: document revision</li>
+ : <li>views: object defining the views. Each field defines a different view.
+ : The field name is the name of the view and has the following content:
+ : <ul>
+ : <li>map: view map function</li>
+ : <li>reduce: view reduce function (optional)</li>
+ : </ul>
+ : </li>
+ : <li>indexes: object defining the view indexes. Each field defines a different index.
+ : The field name is the name of the index and has the following content:
+ : <ul>
+ : <li>analyzer: Name of the analyzer to be used or an object with the following fields:
+ : <ul>
+ : <li>name: Name of the analyzer</li>
+ : <li>stopwords: An array of stop words. Stop words are words that should not be indexed.</li>
+ : </ul>
+ : </li>
+ : <li>index: Function that handles the indexing</li>
+ : </ul>
+ : </li>
+ : </ul>
+ : </p>
+ :
+ : <h4>Return value</h4>
+ :
+ : <p>The format of the returned object is the following and contains
+ : the document id and revision.
+ : <pre>
+ : {
+ : "ok":true,
+ : "id":"DocID",
+ : "rev":"1-764b9b11845fd0b73cfa0e61acc74ecf"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document A document
+ : @param $options An object specifying additional request options
+ : @return An object which specifies the document id and its new revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:DOCUMENT-MALFORMED Malformed document object
+ : @error cloudant:OPTIONS Malformed options object
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:create-or-update-document($connection as anyURI, $database as string, $document as object, $options as object) as object
+{
+ let $document-id := cloudant:mandatory-string-parameter("_id", $document)
+ let $document-rev := cloudant:string-parameter("_rev", (), $document)
+ let $document-arg := if ($document-rev)
+ then "?rev=" || $document-rev
+ else ""
+ let $response:= cloudant:send-request(
+ {|
+ {
+ method : "PUT",
+ body:
+ {
+ "media-type": "application/json",
+ "content": fn:serialize($document)
+ }
+ },
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/" || cloudant:prepare-document-id($document-id) || $document-arg || cloudant:query-arguments(($document-arg eq ""), $options), $options)
+ |})
+ return
+ switch ($response.status)
+ case 201 return cloudant:parse-object($response.body.content)
+ case 202 return cloudant:parse-object($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+
+(:~
+ : <p>Deletes the specified document from a database.</p>
+ :
+ : <p>The latest document revision must be specified.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:delete-document($connection, "db", "DocID", "3-7c4740b4dcf26683e941d6641c00c39d")</pre>.
+ : </p>
+ :
+ : <h4>Deleting a design document</h4>
+ :
+ : <p>To delete a design document the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:delete-document($connection, "db", "_design/DesDocID", "3-7c4740b4dcf26683e941d6641c00c39d")</pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ :
+ : <p>The returned object reports the document id and its
+ : new revision, as follows:
+ : <pre>
+ : {
+ : "id":"DocID",
+ : "ok":true,
+ : "rev":"4-2719fd41187c60762ff584761b714cfb"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $document-rev A document revision
+ : @return An object which specifies the document id and its new revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:REVISION Specified revision is missing, invalid or not the latest.
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:delete-document($connection as anyURI, $database as string, $document-id as string, $document-rev as string) as object
+{
+ cloudant:delete-document($connection, $database, $document-id, $document-rev, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Deletes the specified document from a database.</p>
+ :
+ : <p>The latest document revision must be specified.</p>
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:delete-document($connection, "db", "DocID", "3-7c4740b4dcf26683e941d6641c00c39d",
+ : {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <h4>Deleting a design document</h4>
+ :
+ : <p>To delete a design document the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:delete-document($connection, "db", "_design/DesDocID", "3-7c4740b4dcf26683e941d6641c00c39d",
+ : {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ : <p>The returned object reports the document id and its
+ : new revision, as follows:
+ : <pre>
+ : {
+ : "id":"DocID",
+ : "ok":true,
+ : "rev":"4-2719fd41187c60762ff584761b714cfb"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $document-rev A document revision
+ : @param $options An object specifying additional request options
+ : @return An object which specifies the document id and its new revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:REVISION Specified revision is missing, invalid or not the latest.
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:delete-document($connection as anyURI, $database as string, $document-id as string, $document-rev as string, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ {|
+ { method : "DELETE" },
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/" || cloudant:prepare-document-id($document-id) || "?rev=" || $document-rev || cloudant:query-arguments(false, $options), $options)
+ |})
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-object($response.body.content)
+ case 409 return fn:error(xs:QName("cloudant:REVISION"),"Specified revision is missing, invalid or not the latest.")
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Retrieves the specified document attachment.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:attachment($connection, "db", "DocID", "Attachment")</pre>.
+ : </p>
+ :
+ : <h4>Retrieving a design document attachment.</h4>
+ :
+ : <p>To retrieve a design document attachment the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:attachment($connection, "db", "_design/DocID", "Attachment")</pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ :
+ : <p>The returned object reports the media-type of the attachment as
+ : it was specified when the attachment was submitted to the database and
+ : its raw content.
+ : The format of the returned object is the following:
+ : <pre>
+ : {
+ : "media-type": "text/plain",
+ : "content" : "Hello World"
+ : }
+ : </pre>
+ : </p>
+ :
+ : <p>The type of the content field is determined by the media-type returned by the
+ : server. If the media-type indicates that the body content is textual,
+ : then the content has type string, base64Binary otherwise.
+ : Specifically, the body content is considered textual only if the MIME-type specified in
+ : the media-type is one of:
+ : <ul>
+ : <li>"application/json"</li>
+ : <li>"application/x-javascript"</li>
+ : <li>"application/xml"</li>
+ : <li>"application/xml-external-parsed-entity"</li>
+ : </ul>
+ : or if the MIME-type starts with "text/" or ends with "+xml".</p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $attachment-name An attchment name
+ : @return The specified document attachment
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:attachment($connection as anyURI, $database as string, $document-id as string, $attachment-name as string) as object
+{
+ cloudant:attachment($connection, $database, $document-id, $attachment-name,$cloudant:empty-object)
+};
+
+(:~
+ : <p>Retrieves the specified document attachment.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:attachment($connection, "db", "DocID", "Attachment",
+ : {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <h4>Retrieving a design document attachment.</h4>
+ :
+ : <p>To retrieve a design document attachment the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:attachment($connection, "db", "_design/DocID", "Attachment",
+ : {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ :
+ : <p>The returned object reports the media-type of the attachment as
+ : it was specified when the attachment was submitted to the database and
+ : its raw content.
+ : The format of the returned object is the following:
+ : <pre>
+ : {
+ : "media-type": "text/plain",
+ : "content" : "Hello World"
+ : }
+ : </pre>
+ : </p>
+ :
+ : <p>The type of the content field is determined by the media-type returned by the
+ : server. If the media-type indicates that the body content is textual,
+ : then the content has type string, base64Binary otherwise.
+ : Specifically, the body content is considered textual only if the MIME-type specified in
+ : the media-type is one of:
+ : <ul>
+ : <li>"application/json"</li>
+ : <li>"application/x-javascript"</li>
+ : <li>"application/xml"</li>
+ : <li>"application/xml-external-parsed-entity"</li>
+ : </ul>
+ : or if the MIME-type starts with "text/" or ends with "+xml".</p>
+
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $attachment-name An attchment name
+ : @param $options An object specifying additional request options
+ : @return The specified document attachment
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:ATTACHMENT-NOT-EXISTS Attachment does not exists
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:attachment($connection as anyURI, $database as string, $document-id as string, $attachment-name as string, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ {|
+ cloudant:request($connection, cloudant:encode-database-name($database) || "/" || cloudant:prepare-document-id($document-id) || "/" || fn:encode-for-uri($attachment-name),$options)
+ |})
+ return
+ switch ($response.status)
+ case 200 return $response.body
+ case 404 return fn:error(xs:QName("cloudant:ATTACHMENT-NOT-EXISTS"),"Attachment does not exist.")
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Creates or updates a document attachment.</p>
+ :
+ : <p>The latest document revision must be specified.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:create-or-update-attachment($connection, "db", "FishStew", "8-7c4740b4dcf26683e941d6641c00c39d",
+ : "AttachmentName", "text/plain", "AttachmentContent")</pre>.
+ : </p>
+ :
+ : <h4>Creating or updating a design document attachment.</h4>
+ :
+ : <p>To create or update a design document attachment the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:create-or-update-attachment($connection, "db", "_design/DesDocId", "8-7c4740b4dcf26683e941d6641c00c39d",
+ : "AttachmentName", "text/plain", "AttachmentContent")</pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ :
+ : <p>The returned object reports the document id and its new
+ : revision, as follows:
+ : <pre>
+ : {
+ : "id":"FishStew",
+ : "ok":true,
+ : "rev":"9-247bb19a41bfd9bfdaf5ee6e2e05be74"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $document-rev A document revision
+ : @param $attachment-name The name of the attachment
+ : @param $media-type The media-type of the attachment
+ : @param $attachment The content of the attachment
+ : @return An object containing the document id and its new revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:ATTACHMENT-TYPE Attachment type must be string, base64Binary or hexBinary
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:create-or-update-attachment($connection as anyURI, $database as string, $document-id as string, $document-rev as string, $attachment-name as string, $media-type as string, $attachment as atomic) as object
+{
+ cloudant:create-or-update-attachment($connection, $database, $document-id, $document-rev, $attachment-name, $media-type, $attachment, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Creates or updates a document attachment.</p>
+ :
+ : <p>The latest document revision must be specified.</p>
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:create-or-update-attachment($connection, "db", "FishStew", "8-7c4740b4dcf26683e941d6641c00c39d",
+ : "AttachmentName", "text/plain", "AttachmentContent", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <h4>Creating or updating a design document attachment.</h4>
+ :
+ : <p>To create or update a design document attachment the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:create-or-update-attachment($connection, "db", "_design/DesDocId", "8-7c4740b4dcf26683e941d6641c00c39d",
+ : "AttachmentName", "text/plain", "AttachmentContent", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ : <p>The returned object reports the document id and its new
+ : revision, as follows:
+ : <pre>
+ : {
+ : "id":"FishStew",
+ : "ok":true,
+ : "rev":"9-247bb19a41bfd9bfdaf5ee6e2e05be74"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $document-rev A document revision
+ : @param $attachment-name The name of the attachment
+ : @param $media-type The media-type of the attachment
+ : @param $attachment The content of the attachment
+ : @param $options An object specifying additional request options
+ : @return An object containing the document id and its new revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:ATTACHMENT-TYPE Attachment type must be string, base64Binary or hexBinary
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:create-or-update-attachment($connection as anyURI, $database as string, $document-id as string, $document-rev as string, $attachment-name as string, $media-type as string, $attachment as atomic, $options as object) as object
+{
+ typeswitch($attachment)
+ case string return ();
+ case base64Binary return ();
+ case hexBinary return ();
+ default return fn:error(xs:QName("cloudant:ATTACHMENT-TYPE"), "The type of the attachment content must be string, base64Binary or hexBinary.");
+ let $response:= cloudant:send-request(
+ {|
+ {
+ method : "PUT",
+ body:
+ {
+ "media-type": $media-type,
+ "content": $attachment
+ }
+ },
+ cloudant:request($connection, cloudant:encode-database-name($database) || "/" || cloudant:prepare-document-id($document-id) || "/" || $attachment-name || "?rev=" || $document-rev || cloudant:query-arguments(false, $options), $options)
+ |})
+ return
+ switch ($response.status)
+ case 201 return cloudant:parse-object($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Deletes the specified attachment.</p>
+ :
+ : <p>The latest document revision must be specified.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:delete-attachment($connection, "db", "FishStew", "8-7c4740b4dcf26683e941d6641c00c39d",
+ : "AttachmentName")</pre>.
+ : </p>
+ :
+ : <h4>Deleting a design document attachment.</h4>
+ :
+ : <p>To delete a design document attachment the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:delete-attachment($connection, "db", "_design/DesDocId", "8-7c4740b4dcf26683e941d6641c00c39d",
+ : "AttachmentName", "text/plain", "AttachmentContent")</pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ : <p>The returned object reports the document id and its new
+ : revision, as follows:
+ : <pre>
+ : {
+ : "id":"FishStew",
+ : "ok":true,
+ : "rev":"9-247bb19a41bfd9bfdaf5ee6e2e05be74"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $document-rev A document revision
+ : @param $attachment-name The name of the attachment
+ : @return An object containing the document id and its new revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:ATTACHMENT-NOT-EXISTS Attachment does not exists
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:ATTACHMENT-TYPE Attachment type must be string, base64Binary or hexBinary
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:delete-attachment($connection as anyURI, $database as string, $document-id as string, $document-rev as string, $attachment-name as string) as object
+{
+ cloudant:delete-attachment($connection, $database, $document-id, $document-rev, $attachment-name, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Deletes the specified attachment.</p>
+ :
+ : <p>The latest document revision must be specified.</p>
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:delete-attachment($connection, "db", "FishStew", "8-7c4740b4dcf26683e941d6641c00c39d",
+ : "AttachmentName", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <h4>Deleting a design document attachment.</h4>
+ :
+ : <p>To delete a design document attachment the document id must
+ : start with <code>_design/</code>.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:delete-attachment($connection, "db", "_design/DesDocId", "8-7c4740b4dcf26683e941d6641c00c39d",
+ : "AttachmentName", "text/plain", "AttachmentContent", {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <h4>Return value</h4>
+ : <p>The returned object reports the document id and its new
+ : revision, as follows:
+ : <pre>
+ : {
+ : "id":"FishStew",
+ : "ok":true,
+ : "rev":"9-247bb19a41bfd9bfdaf5ee6e2e05be74"
+ : }
+ : </pre>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $document-id A document identifier
+ : @param $document-rev A document revision
+ : @param $attachment-name The name of the attachment
+ : @param $options An object specifying additional request options
+ : @return An object containing the document id and its new revision
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:DATABASE-NAME Invalid database name
+ : @error cloudant:ATTACHMENT-NOT-EXISTS Attachment does not exists
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:ATTACHMENT-TYPE Attachment type must be string, base64Binary or hexBinary
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:delete-attachment($connection as anyURI, $database as string, $document-id as string, $document-rev as string, $attachment-name as string, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ {|
+ {
+ method : "DELETE"
+ },
+ cloudant:request($connection, cloudant:encode-database-name($database) || "/" || cloudant:prepare-document-id($document-id) || "/" || fn:encode-for-uri($attachment-name) || "?rev=" || fn:encode-for-uri($document-rev) || cloudant:query-arguments(false, $options),$options)
+ |})
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-object($response.body.content)
+ case 404 return cloudant:error(xs:QName("cloudant:ATTACHMENT-NOT-EXISTS"),"Attachment does not exist", $response)
+ case 409 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Returns a JSON object describing all the documents in a given view.</p>
+ :
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:all-view-documents($connection, "db", "recipes", "by_title")</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "offset" : 0,
+ : "rows" :
+ : [
+ : {
+ : "id" : "3-tiersalmonspinachandavocadoterrine",
+ : "key" : "3-tier salmon, spinach and avocado terrine",
+ : "value" : ["3-tier salmon, spinach and avocado terrine"]
+ : },
+ : {
+ : "id" : "Aberffrawcake",
+ : "key" : "Aberffraw cake",
+ : "value" : ["Aberffraw cake"]
+ : },
+ : {
+ : "id" : "Adukiandorangecasserole-microwave",
+ : "key" : "Aduki and orange casserole - microwave",
+ : "value" : ["Aduki and orange casserole - microwave"]
+ : }
+ : ],
+ : "total_rows" : 3
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>offset: offset where the document list started.</li>
+ : <li>rows: array of document objects, each containing id, key and revision number.</li>
+ : <li>total_rows: number of documents in the database.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $design-document A design document name
+ : @param $view A view name
+ : @return An object listing all documents in the specified view
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:all-view-documents($connection as anyURI, $database as string, $design-document as string, $view as string) as object
+{
+ cloudant:all-view-documents($connection, $database, $design-document, $view, $cloudant:empty-object)
+};
+
+
+
+(:~
+ : <p>Returns a JSON object describing all the documents in a given view.</p>
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>descending: return the documents in descending by key order (boolean, default: false)</li>
+ : <li>endkey: stop returning records when the specified key is reached (string)</li>
+ : <li>endkey_docid: stop returning records when the specified document ID is reached (string)</li>
+ : <li>group: group the results using the reduce function to a group or single row (boolean, default: false)</li>
+ : <li>group_level: specify the group level to be used (numeric)</li>
+ : <li>include_docs: include the full content of the documents in the return (boolean, default: false)</li>
+ : <li>inclusive_end: specifies whether the specified end key should be included in the result (boolean, default: true)</li>
+ : <li>key: return only documents that match the specified key (string)</li>
+ : <li>limit: limit the number of the returned documents to the specified number (numeric)</li>
+ : <li>reduce: use the reduction function (boolean, default: true)</li>
+ : <li>skip: skip this number of records before starting to return the results (numeric, default: 0)</li>
+ : <li>stale: allow the results from a stale view to be used (string, allowed value: "ok")</li>
+ : <li>startkey: start returning records when the specified key is reached (string)</li>
+ : <li>startkey_docid: start returning records when the specified document ID is reached (string)</li>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:all-view-documents($connection, "db", "recipes", "by_title",
+ : {"database-owner" : "username"})</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "offset" : 0,
+ : "rows" :
+ : [
+ : {
+ : "id" : "3-tiersalmonspinachandavocadoterrine",
+ : "key" : "3-tier salmon, spinach and avocado terrine",
+ : "value" : ["3-tier salmon, spinach and avocado terrine"]
+ : },
+ : {
+ : "id" : "Aberffrawcake",
+ : "key" : "Aberffraw cake",
+ : "value" : ["Aberffraw cake"]
+ : },
+ : {
+ : "id" : "Adukiandorangecasserole-microwave",
+ : "key" : "Aduki and orange casserole - microwave",
+ : "value" : ["Aduki and orange casserole - microwave"]
+ : }
+ : ],
+ : "total_rows" : 3
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>offset: offset where the document list started.</li>
+ : <li>rows: array of document objects, each containing id, key and revision number.</li>
+ : <li>total_rows: number of documents in the database.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $design-document A design document name
+ : @param $view A view name
+ : @param $options An object specifying additional request options
+ : @return An object listing all documents in the specified view
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:all-view-documents($connection as anyURI, $database as string, $design-document as string, $view as string, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/_design/" || $design-document || "/_view/" || $view || cloudant:query-arguments(true, $options), $options)
+ )
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-object($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>List the specified documents in a given view.</p>
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:multiple-view-documents($connection, "db", "recipes", "by_ingredient",
+ : ("claret", "clear apple juice"))
+ : </pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "total_rows" : 26484,
+ : "rows" : [
+ : {
+ : "value" : ["Scotch collops"]],
+ : "id" : "Scotchcollops",
+ : "key" : "claret"
+ : },
+ : {
+ : "value" : ["Stand pie"],
+ : "id" : "Standpie",
+ : "key" : "clear apple juice"
+ : }
+ : ],
+ : "offset" : 6324
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>offset: offset where the document list started.</li>
+ : <li>rows: array of document objects, each containing id, key and revision number.</li>
+ : <li>total_rows: number of documents in the database.</li>
+ : <li>update_seq: current update sequence database.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $design-document A design document name
+ : @param $view A view name
+ : @param $keys The keys of the documents which must be retrieved
+ : @return An object listing all the specified documents in the specified view
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:multiple-view-documents($connection as anyURI, $database as string, $design-document as string, $view as string, $keys as string*) as object
+{
+ cloudant:multiple-view-documents($connection, $database, $design-document, $view, $keys, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Lists the specified documents in a given view.</p>
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>descending: return the documents in descending by key order (boolean, default: false).</li>
+ : <li>endkey: stop returning records when the specified key is reached (string).</li>
+ : <li>endkey_docid: stop returning records when the specified document ID is reached (string).</li>
+ : <li>group: group the results using the reduce function to a group or single row (boolean, default: false).</li>
+ : <li>group_level: specify the group level to be used (numeric).</li>
+ : <li>include_docs: include the full content of the documents in the return (boolean, default: false).</li>
+ : <li>inclusive_end: specifies whether the specified end key should be included in the result (boolean, default: true).</li>
+ : <li>key: return only documents that match the specified key (string).</li>
+ : <li>limit: limit the number of the returned documents to the specified number (numeric).</li>
+ : <li>reduce: use the reduction function (boolean, default: true).</li>
+ : <li>skip: skip this number of records before starting to return the results (numeric, default: 0).</li>
+ : <li>stale: allow the results from a stale view to be used (string, allowed value: "ok").</li>
+ : <li>startkey: start returning records when the specified key is reached (string).</li>
+ : <li>startkey_docid: start returning records when the specified document ID is reached (string).</li>
+ : <li>database-owner: specifies the database owner (string, default: connection user).</li>
+ : </ul>
+ : </p>
+ :
+ : <p>For example,
+ : <pre>cloudant:multiple-view-documents($connection, "db", "recipes", "by_ingredient",
+ : ("claret", "clear apple juice"), {"database-owner": "username"})
+ : </pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "total_rows" : 26484,
+ : "rows" : [
+ : {
+ : "value" : ["Scotch collops"]],
+ : "id" : "Scotchcollops",
+ : "key" : "claret"
+ : },
+ : {
+ : "value" : ["Stand pie"],
+ : "id" : "Standpie",
+ : "key" : "clear apple juice"
+ : }
+ : ],
+ : "offset" : 6324
+ : }
+ : </pre>
+ : </p>
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>offset: offset where the document list started.</li>
+ : <li>rows: array of document objects, each containing id, key and revision number.</li>
+ : <li>total_rows: number of documents in the database.</li>
+ : <li>update_seq: current update sequence database.</li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $design-document A design document name
+ : @param $view A view name
+ : @param $keys The keys of the documents which must be retrieved
+ : @param $options An object specifying additional request options
+ : @return An object listing all the specified documents in the specified view
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:multiple-view-documents($connection as anyURI, $database as string, $design-document as string, $view as string, $keys as string*, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ {|
+ {
+ method : "POST",
+ body:
+ {
+ "media-type": "application/json",
+ "content": fn:serialize(
+ {
+ keys: [$keys]
+ })
+ }
+ },
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/_design/" || $design-document || "/_view/" || $view || cloudant:query-arguments(true, $options), $options)
+ |})
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-object($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:~
+ : <p>Exectues a Lucene query against a view and returns the query result.</p>
+ :
+ : <p>This method searches for documents whose index fields match the Lucene query.
+ : Which fields of a document are indexed and how is determined by the index functions
+ : in the design document.</p>
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ :
+ : <p>For example,
+ : <pre>cloudant:lucene-query($connection, "db", "designdoc", "view", "a*")</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "total_rows": 3,
+ : "bookmark": "g1AAAACWeJzLYWBgYMpgTmFQSElKzi9KdUhJMtbLTS3KLElMT9VLzskvTUnMK9HLSy3JAalMcgCSSfX____PAvPdQHwQSGTIIt6UPBaQlgNA6j_CJPsPcJOyANNEKzY",
+ : "rows":
+ : [
+ : {
+ : "id": "dd828eb4-c3f1-470f-aeff-c375ef70e4ad",
+ : "order": [0.0, 1],
+ : "fields":
+ : {
+ : "default": "aa",
+ : "foo": 0.0
+ : }
+ : },
+ : {
+ : "id": "ea522cf1-eb8e-4477-aa92-d1fa459bb216",
+ : "order": [1.0, 0],
+ : "fields":
+ : {
+ : "default": "ab",
+ : "foo": 1.0
+ : }
+ : },
+ : {
+ : "id": "c838baed-d573-43ea-9c34-621cf0f13301",
+ : "order": [2.0, 0],
+ : "fields":
+ : {
+ : "default": "ac",
+ : "foo": 2.0
+ : }
+ : }
+ : ]
+ : }
+ : </pre>
+ : </p>
+ :
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>total_rows: number of results returned.</li>
+ : <li>bookmark: string to be submitted in the next query to page through results.
+ : If this response contained no results, the bookmark will be the same as the
+ : one used to obtain this response.</li>
+ : <li>rows: array of document objects, each document contains the following fields:
+ : <ul>
+ : <li>order: specifies the order with regard to the indexed fields.</li>
+ : <li>fields: Object containing other search indexes.</li>
+ : </ul>
+ : </li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $design-document A design document name
+ : @param $index An index name
+ : @param $query A Lucene query
+ : @return The Lucene query results
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+~:)
+declare %an:sequential function cloudant:lucene-query($connection as anyURI, $database as string, $design-document as string, $index as string, $query as string) as object
+{
+ cloudant:lucene-query($connection, $database, $design-document, $index, $query, $cloudant:empty-object)
+};
+
+(:~
+ : <p>Executes a Lucene query against a view and returns the query result.</p>
+ :
+ : <p>This method searches for documents whose index fields match the Lucene query.
+ : Which fields of a document are indexed and how is determined by the index functions
+ : in the design document.</p>
+ :
+ : <p>This function allows to specify an additional options object.
+ : The following options are supported:
+ : <ul>
+ : <li>bookmark: A bookmark that was received from a previous search. This allows you to page
+ : through the results. If there are no more results after the bookmark, you will get a response with
+ : an empty rows array and the same bookmark. That way you can determine that you have reached
+ : the end of the result list (string).</li>
+ : <li>stale: allow the results from a stale view to be used (string, allowed value: "ok").</li>
+ : <li>limit: limit the number of the returned documents to the specified number (numeric).</li>
+ : <li>include_docs: include the full content of the documents in the return (boolean, default: false).</li>
+ : <li>sort: specifies the sort order of the results. A JSON string of the form <code>"fieldname<type>"</code>
+ : or <code>-fieldname<type></code> for descending order, where fieldname is the name of a string or
+ : number field and type is either number or string. The type part is optional and defaults to number.
+ : Some examples are <code>"foo"</code>, <code>"-foo"</code>, <code>"bar<string>"</code>,
+ : <code>"-foo<number>"</code>. String fields used for sorting must not be analyzed fields. The field(s)
+ : used for sorting must be indexed by the same indexer used for the search query. Alternatively, a JSON array
+ : of such strings is allowed.</li>
+ : </ul>
+ : </p>
+ :
+ : <p>The information is returned as a JSON structure containing meta information
+ : about the return structure, and the list of documents each with its ID, revision
+ : and key. The key is generated from the document ID.</p>
+ : <p>For example,
+ : <pre>cloudant:lucene-query($connection, "db", "designdoc", "view", "a*",
+ : {"database-owner": "username"})</pre>.
+ : </p>
+ :
+ : <p>An object with the following format is returned:
+ : <pre>
+ : {
+ : "total_rows": 3,
+ : "bookmark": "g1AAAACWeJzLYWBgYMpgTmFQSElKzi9KdUhJMtbLTS3KLElMT9VLzskvTUnMK9HLSy3JAalMcgCSSfX____PAvPdQHwQSGTIIt6UPBaQlgNA6j_CJPsPcJOyANNEKzY",
+ : "rows":
+ : [
+ : {
+ : "id": "dd828eb4-c3f1-470f-aeff-c375ef70e4ad",
+ : "order": [0.0, 1],
+ : "fields":
+ : {
+ : "default": "aa",
+ : "foo": 0.0
+ : }
+ : },
+ : {
+ : "id": "ea522cf1-eb8e-4477-aa92-d1fa459bb216",
+ : "order": [1.0, 0],
+ : "fields":
+ : {
+ : "default": "ab",
+ : "foo": 1.0
+ : }
+ : },
+ : {
+ : "id": "c838baed-d573-43ea-9c34-621cf0f13301",
+ : "order": [2.0, 0],
+ : "fields":
+ : {
+ : "default": "ac",
+ : "foo": 2.0
+ : }
+ : }
+ : ]
+ : }
+ : </pre>
+ : </p>
+ :
+ : <p>The fields have the following meaning:
+ : <ul>
+ : <li>total_rows: number of results returned.</li>
+ : <li>bookmark: string to be submitted in the next query to page through results.
+ : If this response contained no results, the bookmark will be the same as the
+ : one used to obtain this response.</li>
+ : <li>rows: array of document objects, each document contains the following fields:
+ : <ul>
+ : <li>order: specifies the order with regard to the indexed fields.</li>
+ : <li>fields: Object containing other search indexes.</li>
+ : </ul>
+ : </li>
+ : </ul>
+ : </p>
+ :
+ : @param $connection A connection identifier
+ : @param $database A database name
+ : @param $design-document A design document name
+ : @param $index An index name
+ : @param $query A Lucene query
+ : @param $options An object specifying additional request options
+ : @return The Lucene query results
+ :
+ : @error cloudant:AUTHORIZATION Authorization error
+ : @error cloudant:HTTP An HTTP error occurred when issuing the request
+ : @error cloudant:RESPONSE An error occurred parsing the server response
+ : @error cloudant:CONNECTION The specified connection does not exist
+ : @error cloudant:INTERNAL Cloudant internal error
+ : @error cloudant:OPTIONS Malformed options object
+~:)
+declare %an:sequential function cloudant:lucene-query($connection as anyURI, $database as string, $design-document as string, $index as string, $query as string, $options as object) as object
+{
+ let $response:= cloudant:send-request(
+ cloudant:request($connection,cloudant:encode-database-name($database) || "/_design/" || $design-document || "/_search/" || $index || "?q=" || fn:encode-for-uri($query) || cloudant:query-arguments(false, $options), $options)
+ )
+ return
+ switch ($response.status)
+ case 200 return cloudant:parse-object($response.body.content)
+ case 503 return cloudant:error(xs:QName("cloudant:AUTHORIZATION"),"Authorization error", $response)
+ default return cloudant:error($response)
+};
+
+(:
+ : Encodes and verifies a database name
+ :)
+declare %private function cloudant:encode-database-name($database as string) as string
+{
+ if (not(fn:matches($database, "[a-z][a-z0-9_\\$\\(\\)\\+\\-/]*")))
+ then fn:error(xs:QName("cloudant:DATABASE-NAME"),"Invalid database name.")
+ else fn:encode-for-uri($database)
+};
+
+(:
+ : Creates the uri for issuing an api request on the db of the specified owner
+ :)
+declare %private function cloudant:uri( $database-owner as string, $api as string) as string
+{
+ "https://" || $database-owner || ".cloudant.com/" || $api
+};
+
+(:
+ : Computes a request for the given connection, api, and options
+ :)
+declare %private function cloudant:request($connection as anyURI, $api as string, $options as object?) as object
+{
+ let $connection-data:= cloudant:retrieve-connection($connection)
+ return {
+ "href": cloudant:uri(
+ cloudant:string-parameter-encoded("database-owner", $connection-data.default-owner,$options),
+ $api),
+ (: Cookie :)
+ "headers": {Cookie: $connection-data.session-key}
+ }
+};
+
+(:
+ : This function handles an undocumented cloudant error response and raises an appropriate error
+ :)
+declare %private function cloudant:error($response as object) as empty-sequence()
+{
+ cloudant:error(QName("cloudant:INTERNAL"), $response)
+};
+
+(:
+ : This function handles a cloudant error response and raises an appropriate error
+ :)
+declare %private function cloudant:error($error-code as QName, $response as object) as empty-sequence()
+{
+ let $json-error :=
+ try
+ {
+ cloudant:parse-object($response.body.content)
+ }
+ catch *
+ {
+ fn:error($error-code, $response.message || " (" || string($response.status) || ").")
+ }
+ return fn:error($error-code, $json-error.error || " (" || string($response.status) || "), " || $json-error.reason || ".")
+};
+
+declare %private function cloudant:string-parameter($parameter-name as string, $default-value as string?, $options as object?)
+{
+ let $value := cloudant:parameter($parameter-name, $default-value, $options)
+ return if (empty($value) or $value instance of string)
+ then $value
+ else fn:error(xs:QName("cloudant:OPTIONS"), "Malformed options object. The type of the " || $parameter-name || " field must be string.")
+};
+
+declare %private function cloudant:string-parameter-encoded($parameter-name as string, $default-value as string?, $options as object?)
+{
+ let $value := cloudant:parameter($parameter-name, $default-value, $options)
+ return if (empty($value) or $value instance of string)
+ then fn:encode-for-uri($value)
+ else fn:error(xs:QName("cloudant:OPTIONS"), "Malformed options object. The type of the " || $parameter-name || " field must be string.")
+};
+
+declare %private function cloudant:mandatory-string-parameter($parameter-name as string, $document as object?)
+{
+ let $value := cloudant:parameter($parameter-name, (), $document)
+ return if (not(empty($value)) and $value instance of string)
+ then $value
+ else fn:error(xs:QName("cloudant:DOCUMENT-MALFORMED"), "Malformed document. The field " || $parameter-name || " must be present and of type string.")
+};
+
+declare %private function cloudant:parameter($parameter-name as string, $default-value as item?, $options as object?)
+{
+ if (empty($options))
+ then $default-value
+ else if (exists($options($parameter-name)))
+ then $options($parameter-name)
+ else $default-value
+};
+
+declare %private function cloudant:query-arguments($first-parameters as boolean, $options as object?) as string
+{
+ if (empty($options))
+ then ""
+ else
+ string-join(
+ for $key at $i in keys($options)
+ return
+ {
+ (
+ if ($i eq 1 and $first-parameters)
+ then "?"
+ else "&",
+ fn:encode-for-uri($key),
+ "=",
+ fn:encode-for-uri(string($options($key)))
+ )
+ }, "")
+};
+
+(:
+ : This function raises a cloudant error embedding the details contained in the cloudant reponse
+ :)
+declare %private function cloudant:error($error-name as QName, $error-message as string, $response as object ) as object
+{
+ try
+ {
+ let $json-response := cloudant:parse-object($response.body.content)
+ return fn:error($error-name,$error-message || ":" || $json-response.error || ", " || $json-response.reason || ".")
+ }
+ catch *
+ {
+ fn:error($error-name,$error-message || ".")
+ }
+};
+
+(:
+ : This function performs an http-request catching and rethrowing all errors
+ :)
+declare %private %an:sequential function cloudant:send-request($http-request as object) as object
+{
+ try
+ {
+ http:send-request($http-request)
+ }
+ catch *
+ {
+ fn:error(xs:QName("cloudant:HTTP"), $err:description || "(" || $err:code || ")")
+ }
+};
+
+(:
+ : This function parses a serialized json catching and rethrowing all errors
+ :)
+declare %private function cloudant:parse-object($serjson as string) as object
+{
+ try
+ {
+ let $json-object :=parse-json($serjson)
+ return
+ if ($json-object instance of object)
+ then $json-object
+ else fn:error(xs:QName("cloudant:RESPONSE"), "Error parsing the Cloudant server response: unexpected content kind")
+ }
+ catch *
+ {
+ fn:error(xs:QName("cloudant:RESPONSE"), "Error parsing the Cloudant server response: malformed JSON")
+ }
+};
+
+(:
+ : This function parses a serialized json catching and rethrowing all errors
+ :)
+declare %private function cloudant:parse-array($serjson as string) as array
+{
+ try
+ {
+ let $json-array :=parse-json($serjson)
+ return
+ if ($json-array instance of array)
+ then $json-array
+ else fn:error(xs:QName("cloudant:RESPONSE"), "Error parsing the Cloudant server response")
+ }
+ catch *
+ {
+ fn:error(xs:QName("cloudant:RESPONSE"), "Error parsing the Cloudant server response")
+ }
+};
+
+declare %private function cloudant:prepare-document-id($document-id as string) as string
+{
+ if (fn:starts-with($document-id, "_design/"))
+ then fn:concat("_design/", fn:encode-for-uri(fn:substring-after($document-id, "_design/")))
+ else fn:encode-for-uri($document-id)
+};
+
+declare %private function cloudant:store-connection($owner as string, $username as string, $sessionKey as string) as anyURI external;
+declare %private function cloudant:retrieve-connection($connection as anyURI) as object external;
\ No newline at end of file
=== added directory 'modules/cloudant/cloudant.xq.src'
=== added file 'modules/cloudant/cloudant.xq.src/cloudant.cpp'
--- modules/cloudant/cloudant.xq.src/cloudant.cpp 1970-01-01 00:00:00 +0000
+++ modules/cloudant/cloudant.xq.src/cloudant.cpp 2013-07-26 09:22:30 +0000
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2010 28msec Inc.
+ */
+
+#include "cloudant.h"
+
+#ifdef WIN32
+# include <windows.h>
+#else
+# include <time.h>
+#endif
+#include <stdlib.h>
+#include <limits>
+#include <zorba/item_factory.h>
+#include <zorba/empty_sequence.h>
+#include <zorba/singleton_item_sequence.h>
+#include <zorba/user_exception.h>
+#include <zorba/util/uuid.h>
+#include "connectionmap.h"
+
+namespace zorba { namespace cloudantmodule {
+
+ItemFactory* CloudantModule::theFactory = 0;
+
+zorba::String
+CloudantModule::getOneStringArgument(const ExternalFunction::Arguments_t& aArgs, int aIndex) const
+{
+ zorba::Item lItem;
+ zorba::Iterator_t args_iter = aArgs[aIndex]->getIterator();
+ args_iter->open();
+ args_iter->next(lItem);
+ args_iter->close();
+ return lItem.getStringValue();
+}
+
+zorba::ItemSequence_t
+StoreConnectionFunction::evaluate(
+ const ExternalFunction::Arguments_t& aArgs,
+ const zorba::StaticContext* aSContext,
+ const zorba::DynamicContext* aContext) const
+{
+ zorba::String lDefaultOwner = theModule->getOneStringArgument(aArgs, 0);
+ zorba::String lUsername = theModule->getOneStringArgument(aArgs, 1);
+ zorba::String lSessionKey = theModule->getOneStringArgument(aArgs, 2);
+
+ ConnectionMap* lMap = dynamic_cast<ConnectionMap*>(
+ aContext->getExternalFunctionParameter("CloudantConnectionMap"));
+
+ if (!lMap)
+ {
+ lMap = new ConnectionMap(theModule);
+ zorba::DynamicContext* lDynCtx = const_cast<zorba::DynamicContext*>(aContext);
+ lDynCtx->addExternalFunctionParameter("CloudantConnectionMap", lMap);
+ }
+
+ uuid lUUID;
+ uuid::create(&lUUID);
+
+ std::stringstream lStream;
+ lStream << "urn:uuid:" << lUUID;
+ String lIdent(lStream.str());
+
+ lMap->storeConnection(lIdent,lDefaultOwner,lSessionKey);
+
+ zorba::Item lItem = theModule->getItemFactory()->createAnyURI(lStream.str());
+
+ return zorba::ItemSequence_t(new zorba::SingletonItemSequence(lItem));
+}
+
+zorba::ItemSequence_t
+RetrieveConnectionFunction::evaluate(
+ const Arguments_t& aArgs,
+ const zorba::StaticContext*,
+ const zorba::DynamicContext* aContext) const
+{
+ ConnectionMap* lMap = dynamic_cast<ConnectionMap*>(
+ aContext->getExternalFunctionParameter("CloudantConnectionMap"));
+ if (!lMap)
+ theModule->raiseError("CONNECTION","The specified connection does not exist.");
+ Item lData;
+ lData=lMap->getConnection(theModule->getOneStringArgument(aArgs,0));
+ return zorba::ItemSequence_t(new zorba::SingletonItemSequence(lData));
+}
+
+zorba::ExternalFunction*
+CloudantModule::getExternalFunction(const zorba::String& aLocalname)
+{
+ if (aLocalname == "store-connection") {
+ return new StoreConnectionFunction(this);
+ }
+ else if (aLocalname == "retrieve-connection") {
+ return new RetrieveConnectionFunction(this);
+ }
+ return NULL;
+}
+
+void
+CloudantModule::raiseError(const zorba::String& aLocalName, const zorba::String& aMessage) const
+{
+ Item lErrQName = theFactory->createQName(
+ getURI(), aLocalName);
+ throw USER_EXCEPTION(lErrQName, aMessage);
+}
+
+} /* namespace modules */ } /* namespace sausa */
+
+#ifdef WIN32
+# define DLL_EXPORT __declspec(dllexport)
+#else
+# define DLL_EXPORT __attribute__ ((visibility("default")))
+#endif
+extern "C" DLL_EXPORT zorba::ExternalModule* createModule() {
+ return new zorba::cloudantmodule::CloudantModule();
+}
=== added file 'modules/cloudant/cloudant.xq.src/cloudant.h'
--- modules/cloudant/cloudant.xq.src/cloudant.h 1970-01-01 00:00:00 +0000
+++ modules/cloudant/cloudant.xq.src/cloudant.h 2013-07-26 09:22:30 +0000
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2010 28msec Inc.
+ */
+
+#ifndef ZORBA_MODULE_CLOUDANT_H
+#define ZORBA_MODULE_CLOUDANT_H
+
+#include <zorba/zorba.h>
+#include <zorba/error.h>
+#include <zorba/external_module.h>
+#include <zorba/function.h>
+
+namespace zorba { namespace cloudantmodule {
+
+class CloudantModule : public ExternalModule
+{
+ static ItemFactory* theFactory;
+
+ virtual zorba::ExternalFunction*
+ getExternalFunction(const zorba::String& aLocalname);
+
+
+
+public:
+ void
+ raiseError(const zorba::String& aLocalName, const zorba::String& aMessage) const;
+
+ virtual zorba::String
+ getURI() const { return "http://zorba.io/modules/cloudant"; }
+
+ zorba::String
+ getOneStringArgument(const ExternalFunction::Arguments_t& aArgs, int aIndex) const;
+
+ static ItemFactory* getItemFactory()
+ {
+ if(!theFactory)
+ {
+ theFactory = Zorba::getInstance(0)->getItemFactory();
+ }
+ return theFactory;
+ }
+
+};
+
+
+class StoreConnectionFunction : public ContextualExternalFunction
+{
+public:
+
+ StoreConnectionFunction(const CloudantModule* aModule)
+ : theModule(aModule) {}
+
+ virtual ~StoreConnectionFunction() {}
+
+ virtual zorba::String
+ getLocalName() const { return "store-connection"; }
+
+ virtual zorba::ItemSequence_t
+ evaluate(const Arguments_t&,
+ const zorba::StaticContext*,
+ const zorba::DynamicContext*) const;
+
+ virtual String getURI() const
+ {
+ return theModule->getURI();
+ }
+
+protected:
+ const CloudantModule* theModule;
+};
+
+class RetrieveConnectionFunction : public ContextualExternalFunction
+{
+public:
+ RetrieveConnectionFunction(const CloudantModule* aModule)
+ : theModule(aModule) {}
+
+ virtual ~RetrieveConnectionFunction() {}
+
+ virtual zorba::String
+ getLocalName() const { return "retrieve-connection"; }
+
+ virtual zorba::ItemSequence_t
+ evaluate(const Arguments_t&,
+ const zorba::StaticContext*,
+ const zorba::DynamicContext*) const;
+
+ virtual String getURI() const
+ {
+ return theModule->getURI();
+ }
+protected:
+ const CloudantModule* theModule;
+};
+
+
+} /* namespace modules */ } /* namespace sausa */
+
+#endif
+
=== added file 'modules/cloudant/cloudant.xq.src/connectionmap.cpp'
--- modules/cloudant/cloudant.xq.src/connectionmap.cpp 1970-01-01 00:00:00 +0000
+++ modules/cloudant/cloudant.xq.src/connectionmap.cpp 2013-07-26 09:22:30 +0000
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "connectionmap.h"
+#include "zorba/singleton_item_sequence.h"
+#include <curl/curl.h>
+
+namespace zorba
+{
+namespace cloudantmodule
+{
+
+ConnectionData::ConnectionData(const zorba::String& aOwner, const zorba::String& aSessionKey, const CloudantModule* aModule):
+ theDefaultOwner(aOwner),
+ theSessionKey(aSessionKey)
+{
+ zorba::ItemFactory* lFactory = aModule->getItemFactory();
+
+ Item lOwnerValue = lFactory->createString(aOwner);
+ Item lSessionKeyValue = lFactory->createString(aSessionKey);
+
+ Item lOwnerName = lFactory->createString("default-owner");
+ Item lSessionKeyName = lFactory->createString("session-key");
+
+ std::vector<std::pair<Item, Item> > pairs;
+ pairs.push_back(std::pair<Item, Item>(lOwnerName, lOwnerValue));
+ pairs.push_back(std::pair<Item, Item>(lSessionKeyName, lSessionKeyValue));
+
+ theConnectionItem = lFactory->createJSONObject(pairs);
+}
+
+ConnectionMap::ConnectionMap(const CloudantModule* aModule):theModule(aModule)
+{
+ ConnectionMap::theConnectionMap = new ConnectionMap_t();
+}
+
+bool
+ConnectionMap::storeConnection(const zorba::String& aKeyName, const zorba::String& aDefaultOwner, const zorba::String& aSessionKey)
+{
+ std::pair<ConnectionMap_t::iterator, bool> ret;
+ ret = theConnectionMap->insert(std::pair<zorba::String, ConnectionData>(aKeyName, ConnectionData(aDefaultOwner,aSessionKey,theModule)));
+ return ret.second;
+}
+
+zorba::Item
+ConnectionMap::getConnection(const zorba::String& aKeyName)
+{
+ ConnectionMap::ConnectionMap_t::iterator lIter = theConnectionMap->find(aKeyName);
+
+ if (lIter == theConnectionMap->end())
+ theModule->raiseError("CC666","The specified connection does not exist.");
+
+ return lIter->second.theConnectionItem;
+}
+
+void
+ConnectionMap::destroy() throw()
+{
+ if (theConnectionMap)
+ {
+ for (ConnectionMap_t::const_iterator lIter = theConnectionMap->begin();
+ lIter != theConnectionMap->end(); ++lIter)
+ {
+ std::stringstream lURL;
+ lURL << "https://" <<lIter->second.theDefaultOwner <<".cloudant.com/_session";
+
+ CURL* lCURL = curl_easy_init();
+ curl_easy_setopt(lCURL, CURLOPT_URL,lURL.str().c_str());
+ curl_easy_setopt(lCURL, CURLOPT_CUSTOMREQUEST, "DELETE");
+ curl_easy_setopt(lCURL, CURLOPT_TIMEOUT, 10);
+ curl_easy_setopt(lCURL, CURLOPT_COOKIE, lIter->second.theSessionKey.c_str());
+ curl_easy_perform(lCURL);
+ curl_easy_cleanup(lCURL);
+
+ /* Apparently the static context has been already destroyed. Disconnecting via an XQuery function doesn't work.
+ std::vector<ItemSequence_t> lArgs;
+ ItemSequence_t lSeq0 = new SingletonItemSequence(theModule->getItemFactory()->createAnyURI(lIter->second.sessionKey));
+ lArgs.push_back(lSeq0);
+ Item lHofHelper = theModule->getItemFactory()->createQName("http://28msec.io/modules/cloudant", "disconnect");
+ ItemSequence_t lResult = theSctx->invoke(lHofHelper, lArgs);
+ Iterator_t lIter = lResult->getIterator();
+ Item lItemRes;
+ lIter->open();
+ while (lIter->next(lItemRes))
+ {
+ std::cout << lItemRes.getStringValue() << std::endl;
+ }
+ lIter->close();
+
+ declare %an:sequential function cloudant:disconnect($connection as anyURI) as empty-sequence()
+ {
+ let $response:= cloudant:send-request(
+ {|
+ {
+ method: "DELETE"
+ },
+ cloudant:get-request($connection,"_session",())
+ |})
+ return
+ switch ($response.status)
+ case 200 return ()
+ case 503 return cloudant:error(xs:QName("cloudant:CC001"),"Authentication error", $response)
+ default return cloudant:error($response)
+ };
+ */
+ }
+ theConnectionMap->clear();
+ delete theConnectionMap;
+ }
+ delete this;
+};
+
+}}; // namespace zorba, jdbc
=== added file 'modules/cloudant/cloudant.xq.src/connectionmap.h'
--- modules/cloudant/cloudant.xq.src/connectionmap.h 1970-01-01 00:00:00 +0000
+++ modules/cloudant/cloudant.xq.src/connectionmap.h 2013-07-26 09:22:30 +0000
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+#ifndef CLOUDANT_CONNECTION_MAP
+#define CLOUDANT_CONNECTION_MAP
+
+#include <map>
+#include <string>
+#include <zorba/zorba.h>
+#include "cloudant.h"
+
+namespace zorba
+{
+namespace cloudantmodule
+{
+
+struct ConnectionData
+{
+ zorba::String theDefaultOwner;
+ zorba::String theSessionKey;
+ zorba::Item theConnectionItem;
+ ConnectionData(const zorba::String& aOwner, const zorba::String& aSessionKey, const CloudantModule* aModule);
+};
+
+class ConnectionMap : public zorba::ExternalFunctionParameter
+{
+ private:
+ typedef std::map<zorba::String, ConnectionData> ConnectionMap_t;
+ ConnectionMap_t* theConnectionMap;
+ const CloudantModule* theModule;
+ public:
+ ConnectionMap(const CloudantModule* aModule);
+
+ bool
+ storeConnection(const zorba::String& aKeyName, const zorba::String& aDefaultOwner, const zorba::String& aSessionKey);
+
+ zorba::Item
+ getConnection(const zorba::String& aKeyName);
+
+ void
+ destroy() throw();
+};
+
+
+}}; // namespace sausa, modules
+
+#endif
=== modified file 'modules/http-client/CMakeLists.txt'
--- modules/http-client/CMakeLists.txt 2013-07-25 09:30:55 +0000
+++ modules/http-client/CMakeLists.txt 2013-07-26 09:22:30 +0000
@@ -12,18 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-#
-# cURL
-#
-SET (CURL_FOUND)
-IF(ZORBA_SUPPRESS_CURL)
- MESSAGE(STATUS "ZORBA_SUPPRESS_CURL is true - not searching for cURL library")
-ELSE(ZORBA_SUPPRESS_CURL)
- MESSAGE(STATUS "Looking for cURL")
- FIND_PACKAGE(CURL)
-
- IF(CURL_FOUND)
- MESSAGE(STATUS "Found cURL library -- " ${CURL_LIBRARIES})
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
DECLARE_ZORBA_MODULE(FILE xml/http-client-error.xq
@@ -33,28 +21,10 @@
URI "http://expath.org/ns/http-client")
DECLARE_ZORBA_MODULE(FILE xml/http-client.xq VERSION 2.0
- URI "http://www.zorba-xquery.com/modules/http-client"
- LINK_LIBRARIES ${CURL_LIBRARIES})
+ URI "http://www.zorba-xquery.com/modules/http-client")
DECLARE_ZORBA_MODULE(FILE json/http-client.xq VERSION 1.0
URI "http://zorba.io/modules/http-client"
LINK_LIBRARIES ${CURL_LIBRARIES})
-
- IF (WIN32) # Copy certificates for windows only
- IF (MSVC_IDE)
- SET(CACERT_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/../../bin/${CMAKE_BUILD_TYPE}/cacert.pem")
- ELSE (MSVC_IDE)
- SET(CACERT_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/../../bin/cacert.pem")
- ENDIF (MSVC_IDE)
- CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/cacert.pem" ${CACERT_DESTINATION} COPYONLY)
- INSTALL(FILES ${CACERT_DESTINATION} DESTINATION bin)
- ENDIF (WIN32)
-
- ELSE(CURL_FOUND)
- MESSAGE(STATUS "The cURL library was not found - http-client will not be built")
- ENDIF(CURL_FOUND)
-ENDIF(ZORBA_SUPPRESS_CURL)
-SET(ZORBA_HAVE_CURL ${CURL_FOUND} CACHE BOOL "Whether Zorba found cURL" FORCE)
-MARK_AS_ADVANCED(ZORBA_HAVE_CURL)
# vim:set et sw=2 ts=2:
=== added directory 'test/rbkt/ExpQueryResults/zorba/cloudant'
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/all-docs-options.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/all-docs-options.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/all-docs-options.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "total_rows" : 5, "offset" : 0, "rows" : [ { "id" : "document1", "key" : "document1", "value" : { "rev" : "1-d75b851533626d5bd87c863b1d4d4db2" }, "doc" : { "_id" : "document1", "_rev" : "1-d75b851533626d5bd87c863b1d4d4db2", "field1" : "value1", "field2" : "value2", "field3" : "value3" } } ] }
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/all-docs.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/all-docs.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/all-docs.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "total_rows" : 5, "offset" : 0, "rows" : [ { "id" : "document1", "key" : "document1", "value" : { "rev" : "1-d75b851533626d5bd87c863b1d4d4db2" } }, { "id" : "document2", "key" : "document2", "value" : { "rev" : "1-d75b851533626d5bd87c863b1d4d4db2" } }, { "id" : "document3", "key" : "document3", "value" : { "rev" : "1-d75b851533626d5bd87c863b1d4d4db2" } }, { "id" : "document4", "key" : "document4", "value" : { "rev" : "1-d75b851533626d5bd87c863b1d4d4db2" } }, { "id" : "welcome", "key" : "welcome", "value" : { "rev" : "1-b712269aa558821dc48d84d5b263649a" } } ] }
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/all-view-docs.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/all-view-docs.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/all-view-docs.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "total_rows" : 10, "offset" : 0, "rows" : [ { "id" : "kookaburra", "key" : "carnivore", "value" : 1 }, { "id" : "panda", "key" : "carnivore", "value" : 1 }, { "id" : "elephant", "key" : "herbivore", "value" : 1 }, { "id" : "giraffe", "key" : "herbivore", "value" : 1 }, { "id" : "llama", "key" : "herbivore", "value" : 1 }, { "id" : "zebra", "key" : "herbivore", "value" : 1 }, { "id" : "aardvark", "key" : "omnivore", "value" : 1 }, { "id" : "badger", "key" : "omnivore", "value" : 1 }, { "id" : "lemur", "key" : "omnivore", "value" : 1 }, { "id" : "snipe", "key" : "omnivore", "value" : 1 } ] }
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/bulk_docs.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/bulk_docs.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/bulk_docs.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+2 2
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/commit.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/commit.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/commit.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "ok" : true, "instance_start_time" : "0" }
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/connect.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/connect.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/connect.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+true
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/create-delete-database.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/create-delete-database.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/create-delete-database.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+true true true
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/create-get-delete-design-document.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/create-get-delete-design-document.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/create-get-delete-design-document.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+_design/docid world 1 0
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/create-get-delete-document.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/create-get-delete-document.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/create-get-delete-document.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+world 1 0
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/create-update-attachment.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/create-update-attachment.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/create-update-attachment.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "media-type" : "text/plain", "content" : "Hello World" }{ "media-type" : "text/plain", "content" : "Hello JSON" }
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/db-info.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/db-info.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/db-info.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+5 5
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/document-info.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/document-info.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/document-info.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "ok" : true, "id" : "document1", "rev" : "1-d75b851533626d5bd87c863b1d4d4db2", "size" : "118" }
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/get-delete-attachment.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/get-delete-attachment.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/get-delete-attachment.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "media-type" : "text/plain", "content" : "Hello World" }removed
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/head-update-design-document.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/head-update-design-document.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/head-update-design-document.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+_design/docid world json 1
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/head-update-document.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/head-update-document.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/head-update-document.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+world json 1
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/list-databases.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/list-databases.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/list-databases.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+true
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/lucene-query.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/lucene-query.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/lucene-query.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+[ { "id" : "kookaburra", "order" : [ 1.4054651260375977, 0 ], "fields" : { "diet" : "carnivore", "min_length" : 0.28, "class" : "bird", "latin_name" : "Dacelo novaeguineae" } } ]
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/multiple-docs-options.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/multiple-docs-options.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/multiple-docs-options.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "total_rows" : 5, "offset" : 0, "rows" : [ { "id" : "document1", "key" : "document1", "value" : { "rev" : "1-d75b851533626d5bd87c863b1d4d4db2" }, "doc" : { "_id" : "document1", "_rev" : "1-d75b851533626d5bd87c863b1d4d4db2", "field1" : "value1", "field2" : "value2", "field3" : "value3" } }, { "id" : "document2", "key" : "document2", "value" : { "rev" : "1-d75b851533626d5bd87c863b1d4d4db2" }, "doc" : { "_id" : "document2", "_rev" : "1-d75b851533626d5bd87c863b1d4d4db2", "field1" : "value1", "field2" : "value2", "field3" : "value3" } } ] }
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/multiple-docs.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/multiple-docs.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/multiple-docs.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "total_rows" : 5, "offset" : 0, "rows" : [ { "id" : "document1", "key" : "document1", "value" : { "rev" : "1-d75b851533626d5bd87c863b1d4d4db2" } }, { "id" : "document2", "key" : "document2", "value" : { "rev" : "1-d75b851533626d5bd87c863b1d4d4db2" } } ] }
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/multiple-view-docs.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/multiple-view-docs.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/multiple-view-docs.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+{ "total_rows" : 10, "offset" : 7, "rows" : [ { "id" : "kookaburra", "key" : "carnivore", "value" : 1 }, { "id" : "panda", "key" : "carnivore", "value" : 1 } ] }
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/cloudant/update-design-document.xml.res'
--- test/rbkt/ExpQueryResults/zorba/cloudant/update-design-document.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/cloudant/update-design-document.xml.res 2013-07-26 09:22:30 +0000
@@ -0,0 +1,1 @@
+world json 1
\ No newline at end of file
=== added directory 'test/rbkt/Queries/zorba/cloudant'
=== added file 'test/rbkt/Queries/zorba/cloudant/all-docs-options.xq'
--- test/rbkt/Queries/zorba/cloudant/all-docs-options.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/all-docs-options.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,7 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $all-docs := cloudant:all-documents($conn, "crud", {limit: 1, include_docs: true});
+$all-docs
+
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/all-docs.xq'
--- test/rbkt/Queries/zorba/cloudant/all-docs.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/all-docs.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,7 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $all-docs := cloudant:all-documents($conn, "crud");
+$all-docs
+
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/all-view-docs.xq'
--- test/rbkt/Queries/zorba/cloudant/all-view-docs.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/all-view-docs.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,6 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $all-docs := cloudant:all-view-documents($conn, "animaldb","views101","diet");
+$all-docs
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/bulk_docs.xq'
--- test/rbkt/Queries/zorba/cloudant/bulk_docs.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/bulk_docs.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,15 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace r = "http://zorba.io/modules/random";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $database-name := "test-" || r:uuid();
+
+cloudant:create-database($conn, $database-name);
+
+variable $new-docs:= cloudant:bulk-crud($conn, $database-name, ({hello:"world"}, {world: "hello"}));
+
+variable $doc-count-after :=cloudant:database-info($conn,$database-name).doc_count;
+
+cloudant:delete-database($conn, $database-name);
+($doc-count-after , count(members($new-docs)))
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/commit.xq'
--- test/rbkt/Queries/zorba/cloudant/commit.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/commit.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,12 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace r = "http://zorba.io/modules/random";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $database-name := "test-" || r:uuid();
+
+cloudant:create-database($conn, $database-name);
+variable $new-doc:= cloudant:create-document($conn, $database-name, {hello:"world"}, {bulk: true});
+variable $commit := cloudant:commit-changes($conn, $database-name);
+cloudant:delete-database($conn, $database-name);
+$commit
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/connect.xq'
--- test/rbkt/Queries/zorba/cloudant/connect.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/connect.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,12 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+try
+{
+ cloudant:connect("28io","wrong")
+}
+catch cloudant:AUTHORIZATION
+{
+ true
+}
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/create-delete-database.xq'
--- test/rbkt/Queries/zorba/cloudant/create-delete-database.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/create-delete-database.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,49 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace r = "http://zorba.io/modules/random";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $old-dbs := cloudant:list-databases($conn);
+variable $database-name := "test-" || r:uuid();
+variable $before := some $db in members($old-dbs) satisfies $db eq $database-name;
+
+cloudant:create-database($conn, $database-name);
+
+variable $dc :=
+try
+{
+ cloudant:create-database($conn, $database-name)
+}
+catch cloudant:DATABASE-EXISTS
+{
+ true
+};
+
+variable $wn :=
+try
+{
+ cloudant:create-database($conn, "0000")
+}
+catch cloudant:DATABASE-NAME
+{
+ true
+};
+
+
+
+variable $new-dbs := cloudant:list-databases($conn);
+variable $after := some $db in members($old-dbs) satisfies $db eq $database-name;
+
+cloudant:delete-database($conn, $database-name);
+
+variable $dd :=
+try
+{
+ cloudant:delete-database($conn, $database-name)
+}
+catch cloudant:DATABASE-NOT-EXISTS
+{
+ true
+};
+
+($dc, $wn, $dd)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/create-get-delete-design-document.xq'
--- test/rbkt/Queries/zorba/cloudant/create-get-delete-design-document.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/create-get-delete-design-document.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,25 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace r = "http://zorba.io/modules/random";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $database-name := "test-" || r:uuid();
+
+cloudant:create-database($conn, $database-name);
+
+variable $new-doc:= cloudant:create-or-update-document($conn, $database-name,
+{
+_id: "_design/docid",
+hello:"world"
+});
+
+variable $inserted-doc := cloudant:document($conn, $database-name,$new-doc.id);
+
+variable $doc-count-before :=cloudant:database-info($conn,$database-name).doc_count;
+
+cloudant:delete-document($conn,$database-name,$new-doc.id, $new-doc.rev);
+
+variable $doc-count-after :=cloudant:database-info($conn,$database-name).doc_count;
+
+cloudant:delete-database($conn, $database-name);
+($inserted-doc._id, $inserted-doc.hello,$doc-count-before, $doc-count-after)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/create-get-delete-document.xq'
--- test/rbkt/Queries/zorba/cloudant/create-get-delete-document.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/create-get-delete-document.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,21 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace r = "http://zorba.io/modules/random";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $database-name := "test-" || r:uuid();
+
+cloudant:create-database($conn, $database-name);
+
+variable $new-doc:= cloudant:create-document($conn, $database-name, {hello:"world"});
+
+variable $inserted-doc := cloudant:document($conn, $database-name,$new-doc.id);
+
+variable $doc-count-before :=cloudant:database-info($conn,$database-name).doc_count;
+
+cloudant:delete-document($conn,$database-name,$new-doc.id, $new-doc.rev);
+
+variable $doc-count-after :=cloudant:database-info($conn,$database-name).doc_count;
+
+cloudant:delete-database($conn, $database-name);
+($inserted-doc.hello,$doc-count-before, $doc-count-after)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/create-update-attachment.xq'
--- test/rbkt/Queries/zorba/cloudant/create-update-attachment.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/create-update-attachment.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,24 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace base64 = "http://zorba.io/modules/base64";
+import module namespace r = "http://zorba.io/modules/random";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $database-name := "test-" || r:uuid();
+
+cloudant:create-database($conn, $database-name);
+
+variable $new-doc:= cloudant:create-document($conn, $database-name,
+{
+ hello: "world"
+});
+
+variable $updated-doc:= cloudant:create-or-update-attachment($conn, $database-name, $new-doc.id, $new-doc.rev, "greeting", "text/plain", "Hello World");
+variable $attachment:= cloudant:attachment($conn, $database-name, $new-doc.id, "greeting");
+
+variable $updated-updated-doc:= cloudant:create-or-update-attachment($conn, $database-name, $updated-doc.id, $updated-doc.rev, "greeting", "text/plain", "Hello JSON");
+
+variable $updated-attachment:= cloudant:attachment($conn, $database-name, $new-doc.id, "greeting");
+
+cloudant:delete-database($conn, $database-name);
+($attachment, $updated-attachment)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/db-info.xq'
--- test/rbkt/Queries/zorba/cloudant/db-info.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/db-info.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,7 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $db-info := cloudant:database-info($conn,"crud");
+variable $shared-db-info := cloudant:database-info($conn, "crud", {"database-owner": "28io-shared"});
+($db-info.doc_count, $db-info.doc_count)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/document-info.xq'
--- test/rbkt/Queries/zorba/cloudant/document-info.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/document-info.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,7 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $document-info := cloudant:document-info($conn, "crud","document1");
+$document-info
+
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/get-delete-attachment.xq'
--- test/rbkt/Queries/zorba/cloudant/get-delete-attachment.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/get-delete-attachment.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,38 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace base64 = "http://zorba.io/modules/base64";
+import module namespace r = "http://zorba.io/modules/random";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $database-name := "test-" || r:uuid();
+
+cloudant:create-database($conn, $database-name);
+
+variable $new-doc:= cloudant:create-document($conn, $database-name,
+{
+ hello: "world",
+ _attachments:
+ {
+ greeting:
+ {
+ content_type: "text/plain",
+ data: base64:encode("Hello World")
+ }
+ }
+});
+
+variable $attachment:= cloudant:attachment($conn, $database-name, $new-doc.id, "greeting");
+
+variable $updated-doc:= cloudant:delete-attachment($conn, $database-name, $new-doc.id, $new-doc.rev, "greeting");
+variable $deleted-attachment:=
+try
+{
+ cloudant:attachment($conn, $database-name, $new-doc.id, "greeting")
+}
+catch cloudant:ATTACHMENT-NOT-EXISTS
+{
+ "removed"
+};
+
+cloudant:delete-database($conn, $database-name);
+($attachment, $deleted-attachment)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/head-update-design-document.xq'
--- test/rbkt/Queries/zorba/cloudant/head-update-design-document.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/head-update-design-document.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,27 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace r = "http://zorba.io/modules/random";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $database-name := "test-" || r:uuid();
+
+cloudant:create-database($conn, $database-name);
+
+variable $new-doc:= cloudant:create-document($conn, $database-name, {_id: "_design/docid", hello:"world"});
+
+variable $inserted-doc := cloudant:document($conn, $database-name,$new-doc.id);
+variable $inserted-doc-info := cloudant:document-info($conn, $database-name,$new-doc.id);
+
+variable $updated-doc-data := cloudant:create-or-update-document($conn,$database-name,
+ {
+ hello:"json",
+ "_id": $inserted-doc-info.id,
+ "_rev": $inserted-doc-info.rev
+ });
+
+variable $updated-doc := cloudant:document($conn, $database-name, $updated-doc-data.id);
+
+variable $doc-count-after :=cloudant:database-info($conn,$database-name).doc_count;
+
+cloudant:delete-database($conn, $database-name);
+($inserted-doc-info.id,$inserted-doc.hello, $updated-doc.hello, $doc-count-after)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/head-update-document.xq'
--- test/rbkt/Queries/zorba/cloudant/head-update-document.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/head-update-document.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,27 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+import module namespace r = "http://zorba.io/modules/random";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $database-name := "test-" || r:uuid();
+
+cloudant:create-database($conn, $database-name);
+
+variable $new-doc:= cloudant:create-document($conn, $database-name, {hello:"world"});
+
+variable $inserted-doc := cloudant:document($conn, $database-name,$new-doc.id);
+variable $inserted-doc-info := cloudant:document-info($conn, $database-name,$new-doc.id);
+
+variable $updated-doc-data := cloudant:create-or-update-document($conn,$database-name,
+ {
+ hello:"json",
+ "_id": $inserted-doc-info.id,
+ "_rev": $inserted-doc-info.rev
+ });
+
+variable $updated-doc := cloudant:document($conn, $database-name, $updated-doc-data.id);
+
+variable $doc-count-after :=cloudant:database-info($conn,$database-name).doc_count;
+
+cloudant:delete-database($conn, $database-name);
+($inserted-doc.hello, $updated-doc.hello, $doc-count-after)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/list-databases.xq'
--- test/rbkt/Queries/zorba/cloudant/list-databases.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/list-databases.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,6 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $dbs := cloudant:list-databases($conn);
+some $db in members($dbs) satisfies $db eq "crud"
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/lucene-query.xq'
--- test/rbkt/Queries/zorba/cloudant/lucene-query.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/lucene-query.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,5 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+cloudant:lucene-query($conn, "animaldb", "views101", "animals","kookaburra")("rows")
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/multiple-docs-options.xq'
--- test/rbkt/Queries/zorba/cloudant/multiple-docs-options.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/multiple-docs-options.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,7 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $all-docs := cloudant:multiple-documents($conn, "crud",("document1", "document2"), {include_docs: true});
+$all-docs
+
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/multiple-docs.xq'
--- test/rbkt/Queries/zorba/cloudant/multiple-docs.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/multiple-docs.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,7 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $all-docs := cloudant:multiple-documents($conn, "crud",("document1", "document2"));
+$all-docs
+
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/cloudant/multiple-view-docs.xq'
--- test/rbkt/Queries/zorba/cloudant/multiple-view-docs.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/cloudant/multiple-view-docs.xq 2013-07-26 09:22:30 +0000
@@ -0,0 +1,6 @@
+jsoniq version "1.0";
+import module namespace cloudant = "http://zorba.io/modules/cloudant";
+
+variable $conn := cloudant:connect("28io","Oi7aOsWS4yy4");
+variable $all-docs := cloudant:multiple-view-documents($conn, "animaldb","views101","diet", ("carnivore"));
+$all-docs
\ No newline at end of file
Follow ups
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Federico Cavalieri, 2013-08-02
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Matthias Brantner, 2013-07-31
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Chris Hillery, 2013-07-30
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Federico Cavalieri, 2013-07-29
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Federico Cavalieri, 2013-07-26
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Chris Hillery, 2013-07-26
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Chris Hillery, 2013-07-26
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Federico Cavalieri, 2013-07-26
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Chris Hillery, 2013-07-26
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Chris Hillery, 2013-07-26
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Federico Cavalieri, 2013-07-26
-
Re: [Merge] lp:~zorba-coders/zorba/feature-cloudant into lp:zorba
From: Chris Hillery, 2013-07-26