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

95 lines
1.5 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-11-16 01:46:44 +00:00
,set(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-11-16 01:46:44 +00:00
,get() {
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-11-16 01:46:44 +00:00
,set(x) {
2022-05-30 01:30:33 +00:00
this._stmt = new Sql.String({query: x});
this.onChange();
2015-07-17 14:34:42 +00:00
}
2022-11-16 01:46:44 +00:00
,get() {
2022-05-30 01:30:33 +00:00
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-11-16 01:46:44 +00:00
,set(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-11-16 01:46:44 +00:00
,get() {
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
2022-11-16 01:46:44 +00:00
,set(x) {
2022-05-30 01:30:33 +00:00
this.link({_lot: x}, {'change': this.onChange});
this.onChange();
2015-07-17 14:34:42 +00:00
}
2022-11-16 01:46:44 +00:00
,get() {
2022-05-30 01:30:33 +00:00
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-11-16 01:46:44 +00:00
,appendChild(child) {
2018-05-17 12:08:43 +00:00
if (child.nodeType === Node.TEXT_NODE)
this.query = child.textContent;
}
2022-11-16 01:46:44 +00:00
,loadXml(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-11-28 08:51:31 +00:00
,async execute() {
const resultSet = await this._conn.execStmt(this._stmt, this._lot);
2022-05-30 01:30:33 +00:00
this.emit('ready', resultSet);
2022-11-28 08:51:31 +00:00
return resultSet;
2015-07-17 14:34:42 +00:00
}
2022-11-16 01:46:44 +00:00
,onChange() {
2022-05-30 01:30:33 +00:00
if (this.autoLoad && this._conn && this._stmt && this._lot)
this.execute();
2015-07-17 14:34:42 +00:00
}
});