2016-09-26 09:28:47 +00:00
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
var Stmt = require('./stmt');
|
|
|
|
var Holder = require('./holder');
|
2016-09-26 09:28:47 +00:00
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* Literal SQL string.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-06-06 08:53:59 +00:00
|
|
|
module.exports = new Class({
|
2016-09-26 09:28:47 +00:00
|
|
|
Extends: Stmt
|
2022-05-30 01:30:33 +00:00
|
|
|
,Tag: 'sql-string'
|
2022-06-06 08:53:59 +00:00
|
|
|
,Properties: {
|
|
|
|
query: {
|
2015-01-23 13:09:30 +00:00
|
|
|
type: String
|
|
|
|
,value: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,regexp: /#\w+/g
|
2022-05-30 01:30:33 +00:00
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,appendChild: function(child) {
|
2022-05-30 01:30:33 +00:00
|
|
|
if (child.nodeType === Node.TEXT_NODE)
|
|
|
|
this.query = child.textContent;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,render: function(params) {
|
2015-01-23 13:09:30 +00:00
|
|
|
if (!this.query)
|
|
|
|
return null;
|
2022-05-30 01:30:33 +00:00
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
function replaceFunc(token) {
|
|
|
|
var holder = new Holder({id: token.substr(1)});
|
|
|
|
return holder.render(params);
|
2022-05-30 01:30:33 +00:00
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
return this.query.replace(this.regexp, replaceFunc);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,findHolders: function() {
|
|
|
|
var ids = this.query.match(this.regexp);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (ids)
|
|
|
|
for (var i = 0; i < ids.length; i++)
|
2022-06-06 08:53:59 +00:00
|
|
|
ids[i] = ids[i].substr(1);
|
2016-01-07 12:58:29 +00:00
|
|
|
|
|
|
|
return ids;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|