hedera-web/js/sql/object.js

105 lines
2.2 KiB
JavaScript
Raw Normal View History

/**
* Base class for all objects on this library.
2022-05-26 06:08:31 +00:00
*/
2022-05-28 19:27:36 +00:00
module.exports = new Class({
Extends: Vn.Object
2022-05-30 01:30:33 +00:00
/**
* 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.
*
2022-05-30 01:30:33 +00:00
* @param {Object} params The params used to render the object
* @return {string} The SQL string
2022-05-26 06:08:31 +00:00
*/
2022-05-30 01:30:33 +00:00
,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;
}
/**
2022-05-30 01:30:33 +00:00
* Renders an objects array using a separator.
*
2022-05-30 01:30:33 +00:00
* @param {Array} list The objects array
* @param {Object} params The parameters
* @param {String} separator The separator between items
* @return {string} The rendered SQL string
2022-05-26 06:08:31 +00:00
*/
2022-05-30 01:30:33 +00:00
,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 '';
}
/**
2022-05-30 01:30:33 +00:00
* Renders the object if it's defined.
*
2022-05-30 01:30:33 +00:00
* @param {String} prefix The rendered string prefix
* @return {string} The rendered object with its prefix
2022-05-26 06:08:31 +00:00
*/
2022-05-30 01:30:33 +00:00
,renderIfSet: function(object, prefix, params) {
if (object)
return ' '+ prefix +' '+ object.render(params);
else
return '';
}
});