@braindb/core
Version:
markdown-graph-content-layer-database
49 lines (48 loc) • 1.15 kB
JavaScript
import { and, eq } from "drizzle-orm";
import { link } from "./schema.js";
import { Document } from "./Document.js";
export class Link {
idPath;
offset;
// @ts-expect-error it is lazyly initialized only on the request
lnk;
db;
getLnk() {
if (!this.lnk) {
const [lnk] = this.db
.select()
.from(link)
.where(and(eq(link.from, this.idPath), eq(link.start, this.offset)))
.all();
this.lnk = lnk;
}
return this.lnk;
}
constructor(db, idPath, offset) {
this.idPath = idPath;
this.offset = offset;
this.db = db;
}
from() {
return new Document(this.db, this.getLnk().from);
}
to() {
const to = this.getLnk().to;
return to == null ? null : new Document(this.db, to);
}
anchor() {
return this.getLnk().to_anchor;
}
line() {
return this.getLnk().line;
}
column() {
return this.getLnk().column;
}
label() {
return this.getLnk().label;
}
id() {
return this.getLnk().id;
}
}