hedera-web/js/sql/object.js

105 lines
2.1 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
*/
2022-11-16 01:46:44 +00:00
,isReady() {
2022-05-30 01:30:33 +00:00
return true;
}
/**
* Through the query looking for containers.
*
* @return {Array} An array with the names of the found parameters
*/
2022-11-16 01:46:44 +00:00
,findHolders() {}
/**
* 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-11-16 01:46:44 +00:00
,render() {}
2022-05-30 01:30:33 +00:00
/**
* Renders an objects array.
*
* @param {Array} list The objects array
* @param {Object} params The parameters
* @return {string} The rendered SQL string
*/
2022-11-16 01:46:44 +00:00
,renderList(list, params) {
2022-05-30 01:30:33 +00:00
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-11-16 01:46:44 +00:00
,renderListWs(list, params, separator) {
2022-05-30 01:30:33 +00:00
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
*/
2022-11-16 01:46:44 +00:00
,renderIdent(identifier) {
2022-05-30 01:30:33 +00:00
return '`'+ identifier +'`';
}
/**
* Renders a quoted SQL identifier.
*
* @param {String} identifier The identifier
* @return {string} The quoted identifier
*/
2022-11-16 01:46:44 +00:00
,renderPreIdent(identifier) {
2022-05-30 01:30:33 +00:00
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-11-16 01:46:44 +00:00
,renderIfSet(object, prefix, params) {
2022-05-30 01:30:33 +00:00
if (object)
return ' '+ prefix +' '+ object.render(params);
else
return '';
}
});