hedera-web/js/sql/string.js

47 lines
698 B
JavaScript

var Stmt = require ('./stmt');
var Holder = require ('./holder');
/**
* Literal SQL string.
**/
module.exports = new Class
({
Extends: Stmt
,Properties:
{
query:
{
type: String
,value: null
}
}
,regexp: /#\w+/g
,replaceFunc: function (batch, token)
{
var holder = new Holder ({id: token.substr (1)});
return holder.render (batch);
}
,render: function (batch)
{
if (!this.query)
return null;
return this.query.replace (this.regexp, this.replaceFunc.bind (this, batch));
}
,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;
}
});