hedera-web/js/db/query.js

123 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-07-17 14:34:42 +00:00
2016-09-26 09:28:47 +00:00
var Connection = require ('./connection');
module.exports = new Class
2015-07-17 14:34:42 +00:00
({
Extends: Vn.Object
,Tag: 'db-query'
,Properties:
{
/**
* The connection used to execute the statement.
2022-05-26 06:08:31 +00:00
*/
2015-07-17 14:34:42 +00:00
conn:
{
2016-09-26 09:28:47 +00:00
type: Connection
2015-07-17 14:34:42 +00:00
,set: function (x)
{
this._conn = x;
this.onChange ();
}
,get: function ()
{
return this._conn;
}
},
/**
* The model query.
2022-05-26 06:08:31 +00:00
*/
2015-07-17 14:34:42 +00:00
query:
{
type: String
,set: function (x)
{
this._stmt = new Sql.String ({query: x});
this.onChange ();
}
,get: function ()
{
return this._stmt.render (null);
}
},
/**
* The model select statement.
2022-05-26 06:08:31 +00:00
*/
2015-07-17 14:34:42 +00:00
stmt:
{
type: Sql.Stmt
,set: function (x)
{
this._stmt = x;
this.onChange ();
}
,get: function ()
{
return this._stmt;
}
},
/**
* The batch used to execute the statement.
2022-05-26 06:08:31 +00:00
*/
2015-07-17 14:34:42 +00:00
batch:
{
type: Sql.Batch
,set: function (x)
{
this.link ({_batch: x}, {'changed': this.onChange});
this.onChange ();
}
,get: function ()
{
return this._batch;
}
},
/**
* Wether to execute automatically de query que it's ready.
2022-05-26 06:08:31 +00:00
*/
2015-07-17 14:34:42 +00:00
autoLoad:
{
type: Boolean,
value: false
}
}
,initialize: function (props)
{
this.parent (props);
}
2018-05-17 12:08:43 +00:00
,appendChild: function (child)
{
if (child.nodeType === Node.TEXT_NODE)
this.query = child.textContent;
}
2015-07-17 14:34:42 +00:00
,loadXml: function (builder, node)
{
this.parent (builder, node);
var query = node.firstChild.nodeValue;
if (query)
this.query = query;
}
,execute: function ()
{
this._conn.execStmt (this._stmt,
this.onQueryDone.bind (this), this._batch);
}
,onQueryDone: function (resultSet)
{
this.signalEmit ('ready', resultSet);
}
,onChange: function ()
{
if (this.autoLoad && this._conn && this._stmt && this._batch)
this.execute ();
}
});