UNPKG

@sqb/connect

Version:

Multi-dialect database connection framework written with TypeScript

44 lines (43 loc) 1.35 kB
import { AssociationNode } from './association-node.js'; export class LinkChain { target; first; current; constructor(target, targetKey, sourceKey, many) { this.target = target; this.first = this.current = new 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 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; } }