0
1
Fork 0
hedera-web-mindshore/js/db/query.js

98 lines
1.7 KiB
JavaScript
Raw Normal View History

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