1
0
Fork 0

added pretty print for views

This commit is contained in:
Frank Celler 2018-08-03 09:32:56 +02:00
parent 405bb2cd09
commit 54f72cae1b
1 changed files with 79 additions and 58 deletions

View File

@ -1,34 +1,35 @@
/*jshint strict: false */ /*jshint strict: false */
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief ArangoView // @brief ArangoView
// / //
// / @file // @file
// / //
// / DISCLAIMER // DISCLAIMER
// / //
// / Copyright 2013 triagens GmbH, Cologne, Germany // Copyright 2013 triagens GmbH, Cologne, Germany
// / //
// / Licensed under the Apache License, Version 2.0 (the "License") // Licensed under the Apache License, Version 2.0 (the "License")
// / you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// / You may obtain a copy of the License at // You may obtain a copy of the License at
// / //
// / http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// / //
// / Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// / distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// / See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// / limitations under the License. // limitations under the License.
// / //
// / Copyright holder is triAGENS GmbH, Cologne, Germany // Copyright holder is triAGENS GmbH, Cologne, Germany
// / //
// / @author Daniel H. Larkin // @author Daniel H. Larkin
// / @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany // @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany
// ////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////
var internal = require('internal'); const internal = require('internal');
var arangosh = require('@arangodb/arangosh'); const arangosh = require('@arangodb/arangosh');
const ArangoError = require('@arangodb').ArangoError;
// ////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////
// / @brief constructor // / @brief constructor
@ -57,11 +58,31 @@ function ArangoView (database, data) {
exports.ArangoView = ArangoView; exports.ArangoView = ArangoView;
var ArangoError = require('@arangodb').ArangoError; // /////////////////////////////////////////////////////////////////////////////
// @brief pretty print
// /////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////// ArangoView.prototype._PRINT = function (context) {
// / @brief append the waitForSync parameter to a URL const type = this.type();
// ////////////////////////////////////////////////////////////////////////////// const name = this.name();
const colors = internal.COLORS;
const useColor = context.useColor;
context.output += '[ArangoView ';
if (useColor) { context.output += colors.COLOR_NUMBER; }
context.output += this._id;
if (useColor) { context.output += colors.COLOR_RESET; }
context.output += ', "';
if (useColor) { context.output += colors.COLOR_STRING; }
context.output += name || 'unknown';
if (useColor) { context.output += colors.COLOR_RESET; }
context.output += '" (type ' + type + ')]';
};
// /////////////////////////////////////////////////////////////////////////////
// @brief append the waitForSync parameter to a URL
// /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype._appendSyncParameter = function (url, waitForSync) { ArangoView.prototype._appendSyncParameter = function (url, waitForSync) {
if (waitForSync) { if (waitForSync) {
@ -75,9 +96,9 @@ ArangoView.prototype._appendSyncParameter = function (url, waitForSync) {
return url; return url;
}; };
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief append some boolean parameter to a URL // @brief append some boolean parameter to a URL
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype._appendBoolParameter = function (url, name, val) { ArangoView.prototype._appendBoolParameter = function (url, name, val) {
if (url.indexOf('?') === -1) { if (url.indexOf('?') === -1) {
@ -89,9 +110,9 @@ ArangoView.prototype._appendBoolParameter = function (url, name, val) {
return url; return url;
}; };
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief prefix a URL with the database name of the view // @brief prefix a URL with the database name of the view
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype._prefixurl = function (url) { ArangoView.prototype._prefixurl = function (url) {
if (url.substr(0, 5) === '/_db/') { if (url.substr(0, 5) === '/_db/') {
@ -104,9 +125,9 @@ ArangoView.prototype._prefixurl = function (url) {
return this._dbPrefix + '/' + url; return this._dbPrefix + '/' + url;
}; };
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief return the base url for view usage // @brief return the base url for view usage
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype._baseurl = function (suffix) { ArangoView.prototype._baseurl = function (suffix) {
var url = this._database._viewurl(this.name()); var url = this._database._viewurl(this.name());
@ -118,9 +139,9 @@ ArangoView.prototype._baseurl = function (suffix) {
return this._prefixurl(url); return this._prefixurl(url);
}; };
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief converts into an array // @brief converts into an array
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype.toArray = function () { ArangoView.prototype.toArray = function () {
return this.all().toArray(); return this.all().toArray();
@ -150,9 +171,9 @@ ArangoView.prototype._help = function () {
internal.print(helpArangoView); internal.print(helpArangoView);
}; };
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief gets the name of a view // @brief gets the name of a view
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype.name = function () { ArangoView.prototype.name = function () {
if (this._name === null) { if (this._name === null) {
@ -162,9 +183,9 @@ ArangoView.prototype.name = function () {
return this._name; return this._name;
}; };
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief gets the type of a view // @brief gets the type of a view
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype.type = function () { ArangoView.prototype.type = function () {
if (this._type === null) { if (this._type === null) {
@ -174,9 +195,9 @@ ArangoView.prototype.type = function () {
return this._type; return this._type;
}; };
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief gets or sets the properties of a view // @brief gets or sets the properties of a view
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype.properties = function (properties, partialUpdate) { ArangoView.prototype.properties = function (properties, partialUpdate) {
var requestResult; var requestResult;
@ -213,9 +234,9 @@ ArangoView.prototype.properties = function (properties, partialUpdate) {
return result; return result;
}; };
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief drops a view // @brief drops a view
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype.drop = function () { ArangoView.prototype.drop = function () {
var requestResult = this._database._connection.DELETE(this._baseurl()); var requestResult = this._database._connection.DELETE(this._baseurl());
@ -230,9 +251,9 @@ ArangoView.prototype.drop = function () {
} }
}; };
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// / @brief renames a view // @brief renames a view
// ////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
ArangoView.prototype.rename = function (name) { ArangoView.prototype.rename = function (name) {
var body = { name: name }; var body = { name: name };