0
1
Fork 0
hedera-web-mindshore/js/sql/object.js

105 lines
2.2 KiB
JavaScript

/**
* Base class for all objects on this library.
*/
module.exports = new Class({
Extends: Vn.Object
/**
* Gets if the object is ready to be rendered.
*
* @param {Object} params The query parameters
* @return {boolean} %true if the object is ready, %false otherwise
*/
,isReady: function() {
return true;
}
/**
* Through the query looking for containers.
*
* @return {Array} An array with the names of the found parameters
*/
,findHolders: function() {}
/**
* Renders the object as an SQL string.
*
* @param {Object} params The params used to render the object
* @return {string} The SQL string
*/
,render: function() {}
/**
* Renders an objects array.
*
* @param {Array} list The objects array
* @param {Object} params The parameters
* @return {string} The rendered SQL string
*/
,renderList: function(list, params) {
var sql = '';
list.forEach(function(item) {
sql += item.render(params);
})
return sql;
}
/**
* Renders an objects array using a separator.
*
* @param {Array} list The objects array
* @param {Object} params The parameters
* @param {String} separator The separator between items
* @return {string} The rendered SQL string
*/
,renderListWs: function(list, params, separator) {
var sql = '';
list.forEach(function(item, i) {
if (i > 0)
sql += separator;
sql += item.render(params);
})
return sql;
}
/**
* Renders a quoted SQL identifier.
*
* @param {String} identifier The identifier
* @return {string} The quoted identifier
*/
,renderIdent: function(identifier) {
return '`'+ identifier +'`';
}
/**
* Renders a quoted SQL identifier.
*
* @param {String} identifier The identifier
* @return {string} The quoted identifier
*/
,renderPreIdent: function(identifier) {
if (identifier)
return this.renderIdent(identifier) +'.';
else
return '';
}
/**
* Renders the object if it's defined.
*
* @param {String} prefix The rendered string prefix
* @return {string} The rendered object with its prefix
*/
,renderIfSet: function(object, prefix, params) {
if (object)
return ' '+ prefix +' '+ object.render(params);
else
return '';
}
});