@sqb/connect
Version:
Multi-dialect database connection framework written with TypeScript
45 lines (44 loc) • 1.49 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkChain = void 0;
const association_node_js_1 = require("./association-node.js");
class LinkChain {
constructor(target, targetKey, sourceKey, many) {
this.target = target;
this.first = this.current = new association_node_js_1.AssociationNode('', {
many,
target,
source: null,
sourceKey,
targetKey: targetKey,
});
}
where(conditions) {
this.current.conditions = this.current.conditions || [];
if (Array.isArray(conditions))
this.current.conditions.push(...conditions);
else
this.current.conditions.push(conditions);
return this;
}
linkToOne(target, targetColumn, parentColumn) {
return this._newNode(target, targetColumn, parentColumn);
}
linkToMany(target, targetColumn, parentColumn) {
return this._newNode(target, targetColumn, parentColumn, true);
}
_newNode(target, targetKey, parentKey, many = false) {
const child = new association_node_js_1.AssociationNode(this.current.name, {
many,
source: this.current.target,
target,
sourceKey: parentKey,
targetKey: targetKey,
});
child.prior = this.current;
this.current.next = child;
this.current = child;
return this;
}
}
exports.LinkChain = LinkChain;