hedera-web/js/sql/string.js

47 lines
757 B
JavaScript

var Stmt = require('./stmt');
var Holder = require('./holder');
/**
* Literal SQL string.
*/
module.exports = new Class({
Extends: Stmt
,Tag: 'sql-string'
,Properties: {
query: {
type: String
,value: null
}
}
,regexp: /#\w+/g
,appendChild(child) {
if (child.nodeType === Node.TEXT_NODE)
this.query = child.textContent;
}
,render(params) {
if (!this.query)
return null;
function replaceFunc(token) {
var holder = new Holder({id: token.substr(1)});
return holder.render(params);
}
return this.query.replace(this.regexp, replaceFunc);
}
,findHolders() {
var ids = this.query.match(this.regexp);
if (ids)
for (var i = 0; i < ids.length; i++)
ids[i] = ids[i].substr(1);
return ids;
}
});