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

47 lines
757 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-11-16 01:46:44 +00:00
,appendChild(child) {
2022-05-30 01:30:33 +00:00
if (child.nodeType === Node.TEXT_NODE)
this.query = child.textContent;
}
2022-11-16 01:46:44 +00:00
,render(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-11-16 01:46:44 +00:00
,findHolders() {
2022-06-06 08:53:59 +00:00
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;
}
});