@braindb/core
Version:
markdown-graph-content-layer-database
57 lines (56 loc) • 1.39 kB
JavaScript
import { and, eq } from "drizzle-orm";
import { task } from "./schema.js";
import { Document } from "./Document.js";
import { toText } from "./toText.js";
import { mdParser } from "./parser.js";
export class Task {
idPath;
offset;
// @ts-expect-error it is lazyly initialized only on the request
lnk;
db;
getDbRecord() {
if (!this.lnk) {
const [lnk] = this.db
.select()
.from(task)
.where(and(eq(task.from, this.idPath), eq(task.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.getDbRecord().from);
}
ast() {
return this.getDbRecord().ast;
}
checked() {
return this.getDbRecord().checked;
}
line() {
return this.getDbRecord().line;
}
column() {
return this.getDbRecord().column;
}
id() {
return this.getDbRecord().id;
}
/**
* experimental
*/
text() {
return toText(this.getDbRecord().ast);
}
markdown() {
// to support links/wikilinks need to use `getMarkdown`
return mdParser.stringify(this.getDbRecord().ast);
}
}