0
1
Fork 0
hedera-web-mindshore/js/sql/string.js

47 lines
787 B
JavaScript
Raw Normal View History

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
/**
* 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: {
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;
}
2022-06-06 08:53:59 +00:00
,render: function(params) {
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
}
2022-06-06 08:53:59 +00:00
return this.query.replace(this.regexp, replaceFunc);
}
2022-06-06 08:53:59 +00:00
,findHolders: function() {
var ids = this.query.match(this.regexp);
if (ids)
for (var i = 0; i < ids.length; i++)
2022-06-06 08:53:59 +00:00
ids[i] = ids[i].substr(1);
return ids;
}
});