mirror of https://gitee.com/bigwinds/arangodb
added cap doc
This commit is contained in:
parent
6e6b68b1fc
commit
6834d1e3f8
|
@ -0,0 +1,14 @@
|
||||||
|
> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=1786279
|
||||||
|
{ "type" : "cap", "size" : 10 }
|
||||||
|
|
||||||
|
HTTP/1.1 201 Created
|
||||||
|
content-type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"size": 10,
|
||||||
|
"code": 201,
|
||||||
|
"id": "1786279/2769319",
|
||||||
|
"type": "cap",
|
||||||
|
"isNewlyCreated": true,
|
||||||
|
"error": false
|
||||||
|
}
|
|
@ -54,10 +54,7 @@
|
||||||
/// This is an introduction to AvocadoDB's Http interface for indexes in
|
/// This is an introduction to AvocadoDB's Http interface for indexes in
|
||||||
/// general. There are special section for
|
/// general. There are special section for
|
||||||
///
|
///
|
||||||
/// - @ref IndexGeo
|
/// @copydoc IndexesTOC
|
||||||
/// - @ref IndexSkiplist
|
|
||||||
/// - @ref IndexHash
|
|
||||||
/// - @ref IndexPrioQueue
|
|
||||||
///
|
///
|
||||||
/// <hr>
|
/// <hr>
|
||||||
/// @copydoc HttpIndexTOC
|
/// @copydoc HttpIndexTOC
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
/// <ol>
|
/// <ol>
|
||||||
/// <li>@ref IndexCapHttp
|
/// <li>@ref IndexCapHttp
|
||||||
/// <ol>
|
/// <ol>
|
||||||
/// <li>@ref IndexCapHttpEnsureCap "POST /_api/index"</li>
|
/// <li>@ref IndexCapHttpEnsureCapConstraint "POST /_api/index"</li>
|
||||||
/// </ol>
|
/// </ol>
|
||||||
/// </li>
|
/// </li>
|
||||||
/// <li>@ref IndexCapShell
|
/// <li>@ref IndexCapShell
|
||||||
|
@ -59,13 +59,13 @@
|
||||||
/// @section IndexCapHttp Accessing Cap Constraints via Http
|
/// @section IndexCapHttp Accessing Cap Constraints via Http
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
///
|
///
|
||||||
/// @anchor IndexCapHttpEnsureCap
|
/// @anchor IndexCapHttpEnsureCapConstraint
|
||||||
/// @copydetails JSF_POST_api_index_cap
|
/// @copydetails JSF_POST_api_index_cap
|
||||||
///
|
///
|
||||||
/// @section IndexCapShell Accessing Cap Constraints from the Shell
|
/// @section IndexCapShell Accessing Cap Constraints from the Shell
|
||||||
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
||||||
///
|
///
|
||||||
/// @anchor IndexCapShellEnsureGeoIndex
|
/// @anchor IndexCapShellEnsureCapConstraint
|
||||||
/// @copydetails JS_EnsureCapConstraintVocbaseCol
|
/// @copydetails JS_EnsureCapConstraintVocbaseCol
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
/// @page IndexesTOC
|
/// @page IndexesTOC
|
||||||
///
|
///
|
||||||
/// <ol>
|
/// <ol>
|
||||||
|
/// <li>@ref IndexCap</li>
|
||||||
/// <li>@ref IndexGeo</li>
|
/// <li>@ref IndexGeo</li>
|
||||||
/// <li>@ref IndexHash</li>
|
/// <li>@ref IndexHash</li>
|
||||||
/// <li>@ref IndexSkiplist</li>
|
/// <li>@ref IndexSkiplist</li>
|
||||||
|
@ -38,7 +39,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @page Indexes Indexes
|
/// @page Indexes Indexes
|
||||||
///
|
///
|
||||||
/// This is an introduction to AvocadoDB's geo indexes.
|
/// This is an introduction to AvocadoDB's various indexes.
|
||||||
///
|
///
|
||||||
/// <hr>
|
/// <hr>
|
||||||
/// @copydoc IndexesTOC
|
/// @copydoc IndexesTOC
|
||||||
|
|
|
@ -63,11 +63,7 @@
|
||||||
/// This is an introduction to AvocadoDB's interface for indexs in general.
|
/// This is an introduction to AvocadoDB's interface for indexs in general.
|
||||||
/// There are special sections for
|
/// There are special sections for
|
||||||
///
|
///
|
||||||
/// - @ref IndexGeo
|
/// @copydoc IndexesTOC
|
||||||
/// - @ref IndexSkiplist
|
|
||||||
/// - @ref IndexHash
|
|
||||||
/// - @ref IndexPrioQueue
|
|
||||||
/// - @ref IndexCap
|
|
||||||
///
|
///
|
||||||
/// <hr>
|
/// <hr>
|
||||||
/// @copydoc ShellIndexTOC
|
/// @copydoc ShellIndexTOC
|
||||||
|
|
|
@ -61,7 +61,6 @@
|
||||||
/// <ol>
|
/// <ol>
|
||||||
/// <li>@ref SimpleQueryHasNext "@FA{query}.hasNext()"</li>
|
/// <li>@ref SimpleQueryHasNext "@FA{query}.hasNext()"</li>
|
||||||
/// <li>@ref SimpleQueryNext "@FA{query}.next()"</li>
|
/// <li>@ref SimpleQueryNext "@FA{query}.next()"</li>
|
||||||
/// <li>@ref SimpleQueryNextRef "@FA{query}.nextRef()"</li>
|
|
||||||
/// </ol>
|
/// </ol>
|
||||||
/// </li>
|
/// </li>
|
||||||
/// </ol>
|
/// </ol>
|
||||||
|
@ -175,10 +174,6 @@
|
||||||
///
|
///
|
||||||
/// @anchor SimpleQueryNext
|
/// @anchor SimpleQueryNext
|
||||||
/// @copydetails JSF_SimpleQuery_prototype_next
|
/// @copydetails JSF_SimpleQuery_prototype_next
|
||||||
/// <hr>
|
|
||||||
///
|
|
||||||
/// @anchor SimpleQueryNextRef
|
|
||||||
/// @copydetails JSF_SimpleQuery_prototype_nextRef
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
|
|
|
@ -47,6 +47,101 @@ describe AvocadoDB do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## creating a cap constraint
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
context "creating cap constraints:" do
|
||||||
|
before do
|
||||||
|
@cn = "UnitTestsCollectionIndexes"
|
||||||
|
AvocadoDB.drop_collection(@cn)
|
||||||
|
@cid = AvocadoDB.create_collection(@cn)
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
AvocadoDB.drop_collection(@cn)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns either 201 for new or 200 for old indexes" do
|
||||||
|
cmd = api + "?collection=#{@cid}"
|
||||||
|
body = "{ \"type\" : \"cap\", \"size\" : 10 }"
|
||||||
|
doc = AvocadoDB.log_post("#{prefix}-create-new-cap-constraint", cmd, :body => body)
|
||||||
|
|
||||||
|
doc.code.should eq(201)
|
||||||
|
doc.headers['content-type'].should eq("application/json")
|
||||||
|
doc.parsed_response['error'].should eq(false)
|
||||||
|
doc.parsed_response['code'].should eq(201)
|
||||||
|
doc.parsed_response['id'].should_not eq(0)
|
||||||
|
doc.parsed_response['type'].should eq("cap")
|
||||||
|
doc.parsed_response['isNewlyCreated'].should eq(true)
|
||||||
|
|
||||||
|
doc = AvocadoDB.log_post("#{prefix}-create-old-cap-constraint", cmd, :body => body)
|
||||||
|
|
||||||
|
doc.code.should eq(200)
|
||||||
|
doc.headers['content-type'].should eq("application/json")
|
||||||
|
doc.parsed_response['error'].should eq(false)
|
||||||
|
doc.parsed_response['code'].should eq(200)
|
||||||
|
doc.parsed_response['id'].should_not eq(0)
|
||||||
|
doc.parsed_response['type'].should eq("cap")
|
||||||
|
doc.parsed_response['isNewlyCreated'].should eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## creating a cap constraint and unloading
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
context "cap constraints after unload/load:" do
|
||||||
|
before do
|
||||||
|
@cn = "UnitTestsCollectionIndexes"
|
||||||
|
AvocadoDB.drop_collection(@cn)
|
||||||
|
@cid = AvocadoDB.create_collection(@cn)
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
AvocadoDB.drop_collection(@cn)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "survives unload" do
|
||||||
|
cmd = api + "?collection=#{@cid}"
|
||||||
|
body = "{ \"type\" : \"cap\", \"size\" : 10 }"
|
||||||
|
doc = AvocadoDB.post(cmd, :body => body)
|
||||||
|
|
||||||
|
doc.code.should eq(201)
|
||||||
|
doc.headers['content-type'].should eq("application/json")
|
||||||
|
doc.parsed_response['error'].should eq(false)
|
||||||
|
doc.parsed_response['code'].should eq(201)
|
||||||
|
doc.parsed_response['id'].should_not eq(0)
|
||||||
|
|
||||||
|
iid = doc.parsed_response['id']
|
||||||
|
|
||||||
|
cmd = "/_api/collection/#{@cid}/unload"
|
||||||
|
doc = AvocadoDB.put(cmd)
|
||||||
|
|
||||||
|
doc.code.should eq(200)
|
||||||
|
|
||||||
|
cmd = "/_api/collection/#{@cid}"
|
||||||
|
doc = AvocadoDB.get(cmd)
|
||||||
|
doc.code.should eq(200)
|
||||||
|
|
||||||
|
while doc.parsed_response['status'] != 2
|
||||||
|
doc = AvocadoDB.get(cmd)
|
||||||
|
doc.code.should eq(200)
|
||||||
|
end
|
||||||
|
|
||||||
|
cmd = api + "/#{iid}"
|
||||||
|
doc = AvocadoDB.get(cmd)
|
||||||
|
|
||||||
|
doc.code.should eq(200)
|
||||||
|
doc.headers['content-type'].should eq("application/json")
|
||||||
|
doc.parsed_response['error'].should eq(false)
|
||||||
|
doc.parsed_response['code'].should eq(200)
|
||||||
|
doc.parsed_response['id'].should eq(iid)
|
||||||
|
doc.parsed_response['type'].should eq("cap")
|
||||||
|
doc.parsed_response['size'].should eq(10)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
## creating a geo index
|
## creating a geo index
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
|
@ -175,7 +175,7 @@ function GET_api_index (req, res) {
|
||||||
///
|
///
|
||||||
/// Creating a cap collection
|
/// Creating a cap collection
|
||||||
///
|
///
|
||||||
/// @verbinclude api-index-create-cap-constraint
|
/// @verbinclude api-index-create-new-cap-constraint
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function POST_api_index_cap (req, res, collection, body) {
|
function POST_api_index_cap (req, res, collection, body) {
|
||||||
|
@ -188,7 +188,12 @@ function POST_api_index_cap (req, res, collection, body) {
|
||||||
var size = body.size;
|
var size = body.size;
|
||||||
var index = collection.ensureCapConstraint(size);
|
var index = collection.ensureCapConstraint(size);
|
||||||
|
|
||||||
actions.resultOk(req, res, actions.HTTP_OK, index);
|
if (index.isNewlyCreated) {
|
||||||
|
actions.resultOk(req, res, actions.HTTP_CREATED, index);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actions.resultOk(req, res, actions.HTTP_OK, index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
actions.resultException(req, res, err);
|
actions.resultException(req, res, err);
|
||||||
|
|
|
@ -1123,6 +1123,14 @@ static string JS_client_client =
|
||||||
"}\n"
|
"}\n"
|
||||||
"\n"
|
"\n"
|
||||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||||
|
"/// @brief returns all documents\n"
|
||||||
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||||
|
"\n"
|
||||||
|
"AvocadoCollection.prototype.toArray = function () {\n"
|
||||||
|
" return this.all().toArray();\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||||
"/// @brief returns all indexes\n"
|
"/// @brief returns all indexes\n"
|
||||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -1211,6 +1219,22 @@ static string JS_client_client =
|
||||||
"}\n"
|
"}\n"
|
||||||
"\n"
|
"\n"
|
||||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||||
|
"/// @brief adds a cap constraint\n"
|
||||||
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||||
|
"\n"
|
||||||
|
"AvocadoCollection.prototype.ensureCapConstraint = function (size) {\n"
|
||||||
|
" var body;\n"
|
||||||
|
"\n"
|
||||||
|
" body = { type : \"cap\", size : size };\n"
|
||||||
|
"\n"
|
||||||
|
" var requestResult = this._database._connection.POST(\"/_api/index?collection=\" + encodeURIComponent(this._id), JSON.stringify(body));\n"
|
||||||
|
"\n"
|
||||||
|
" TRI_CheckRequestResult(requestResult);\n"
|
||||||
|
"\n"
|
||||||
|
" return requestResult;\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||||
"/// @brief adds an geo index\n"
|
"/// @brief adds an geo index\n"
|
||||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|
Loading…
Reference in New Issue