forked from verdnatura/hedera-web
47 lines
787 B
JavaScript
47 lines
787 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: function(child) {
|
|
if (child.nodeType === Node.TEXT_NODE)
|
|
this.query = child.textContent;
|
|
}
|
|
|
|
,render: function(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: function() {
|
|
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;
|
|
}
|
|
});
|