@itrocks/mysql-maintainer
Version:
Reactively maintains database structure by updating schema and retrying on MySQL errors
92 lines • 3.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mysql = void 0;
const mysql_1 = require("@itrocks/mysql");
const reflect_1 = require("@itrocks/reflect");
const contextual_connection_1 = require("./contextual-connection");
class Mysql extends mysql_1.Mysql {
async connect() {
return contextual_connection_1.Contextual.prototype.applyTo(await super.connect());
}
async deleteId(type, id, property = 'id') {
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push(type);
const result = await super.deleteId(type, id, property);
contexts.pop();
return result;
}
async deleteRelatedId(object, property, id) {
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push(object);
const result = await super.deleteRelatedId(object, property, id);
contexts.pop();
return result;
}
async insert(object) {
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push(object);
const result = await super.insert(object);
contexts.pop();
return result;
}
async insertRelatedId(object, property, id) {
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push(object);
const result = await super.insertRelatedId(object, property, id);
contexts.pop();
return result;
}
async read(type, id) {
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push(type);
const result = await super.read(type, id);
contexts.pop();
return result;
}
async readCollection(object, property, type) {
type ??= new reflect_1.ReflectProperty(object, property).collectionType.elementType.type;
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push([object, type]);
const result = await super.readCollection(object, property, type);
contexts.pop();
return result;
}
async readCollectionIds(object, property, type) {
type ??= new reflect_1.ReflectProperty(object, property).collectionType.elementType.type;
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push([object, type]);
const result = await super.readCollectionIds(object, property, type);
contexts.pop();
return result;
}
async readMultiple(type, ids) {
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push(type);
const result = await super.readMultiple(type, ids);
contexts.pop();
return result;
}
async save(object) {
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push(object);
const result = await super.save(object);
contexts.pop();
return result;
}
async search(type, search = {}, options) {
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push(type);
const result = await super.search(type, search, options);
contexts.pop();
return result;
}
async update(object) {
const contexts = (this.connection ?? await this.connect()).contexts;
contexts.push(object);
const result = await super.update(object);
contexts.pop();
return result;
}
}
exports.Mysql = Mysql;
//# sourceMappingURL=mysql.js.map