mirror of https://gitee.com/bigwinds/arangodb
255 lines
9.0 KiB
JavaScript
255 lines
9.0 KiB
JavaScript
/*jslint indent: 2,
|
|
nomen: true,
|
|
maxlen: 100,
|
|
sloppy: true,
|
|
vars: true,
|
|
white: true,
|
|
plusplus: true */
|
|
/*global require */
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief ArangoCollection
|
|
///
|
|
/// @file
|
|
///
|
|
/// DISCLAIMER
|
|
///
|
|
/// Copyright 2011-2013 triagens GmbH, Cologne, Germany
|
|
///
|
|
/// 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.
|
|
///
|
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
|
///
|
|
/// @author Dr. Frank Celler
|
|
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
(function () {
|
|
var internal = require("internal");
|
|
var console = require("console");
|
|
|
|
var ArangoDatabase = internal.ArangoDatabase;
|
|
var ArangoCollection = internal.ArangoCollection;
|
|
var ArangoError = internal.ArangoError;
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- public constants
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup V8Shell
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief collection is corrupted
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.STATUS_CORRUPTED = 0;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief collection is new born
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.STATUS_NEW_BORN = 1;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief collection is unloaded
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.STATUS_UNLOADED = 2;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief collection is loaded
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.STATUS_LOADED = 3;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief collection is unloading
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.STATUS_UNLOADING = 4;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief collection is deleted
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.STATUS_DELETED = 5;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief document collection
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.TYPE_DOCUMENT = 2;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief edge collection
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.TYPE_EDGE = 3;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief attachment collection
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.TYPE_ATTACHMENT = 4;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- public methods
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup V8Shell
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief converts collection into an array
|
|
///
|
|
/// @FUN{@FA{collection}.toArray()}
|
|
///
|
|
/// Converts the collection into an array of documents. Never use this call
|
|
/// in a production environment.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.prototype.toArray = function() {
|
|
return this.ALL(null, null).documents;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief truncates a collection
|
|
///
|
|
/// @FUN{@FA{collection}.truncate()}
|
|
///
|
|
/// Truncates a @FA{collection}, removing all documents but keeping all its
|
|
/// indexes.
|
|
///
|
|
/// @EXAMPLES
|
|
///
|
|
/// Truncates a collection:
|
|
///
|
|
/// @verbinclude shell_collection-truncate
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.prototype.truncate = function() {
|
|
return internal.db._truncate(this);
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief finds an index of a collection
|
|
///
|
|
/// @FUN{@FA{collection}.index(@FA{index-handle})}
|
|
///
|
|
/// Returns the index with @FA{index-handle} or null if no such index exists.
|
|
///
|
|
/// @EXAMPLES
|
|
///
|
|
/// @verbinclude shell_index-read
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.prototype.index = function(id) {
|
|
var indexes = this.getIndexes();
|
|
var i;
|
|
|
|
if (typeof id === "string") {
|
|
var re = /^([0-9]+)\/([0-9]+)/;
|
|
var pa = re.exec(id);
|
|
|
|
if (pa === null) {
|
|
id = this._id + "/" + id;
|
|
}
|
|
}
|
|
else if (id.hasOwnProperty("id")) {
|
|
id = id.id;
|
|
}
|
|
|
|
for (i = 0; i < indexes.length; ++i) {
|
|
var index = indexes[i];
|
|
|
|
if (index.id === id) {
|
|
return index;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief strng representation of a collection
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.prototype.toString = function(seen, path, names, level) {
|
|
return "[ArangoCollection " + this._id + "]";
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- private methods
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup V8Shell
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief prints a collection
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ArangoCollection.prototype._PRINT = function() {
|
|
var status = "unknown";
|
|
var type = "unknown";
|
|
|
|
switch (this.status()) {
|
|
case ArangoCollection.STATUS_NEW_BORN: status = "new born"; break;
|
|
case ArangoCollection.STATUS_UNLOADED: status = "unloaded"; break;
|
|
case ArangoCollection.STATUS_UNLOADING: status = "unloading"; break;
|
|
case ArangoCollection.STATUS_LOADED: status = "loaded"; break;
|
|
case ArangoCollection.STATUS_CORRUPTED: status = "corrupted"; break;
|
|
case ArangoCollection.STATUS_DELETED: status = "deleted"; break;
|
|
}
|
|
|
|
switch (this.type()) {
|
|
case ArangoCollection.TYPE_DOCUMENT: type = "document"; break;
|
|
case ArangoCollection.TYPE_EDGE: type = "edge"; break;
|
|
case ArangoCollection.TYPE_ATTACHMENT: type = "attachment"; break;
|
|
}
|
|
|
|
internal.output("[ArangoCollection ",
|
|
this._id,
|
|
", \"", this.name(), "\" (type ", type, ", status ", status, ")]");
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
}());
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- END-OF-FILE
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Local Variables:
|
|
// mode: outline-minor
|
|
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @\\}\\)"
|
|
// End:
|