hashOf

tcmts.cli.test.e2e.examples.hashOf · #j3yftnvq · term · runs on the server

uses node:sqlite

import path from "node:path";
import { DatabaseSync } from "node:sqlite";

export const hashOf = (name: string, root: string) => {
  const db = new DatabaseSync(path.join(root, ".tcm", "codebase.sqlite"), { readOnly: true });
  try {
    return (db.prepare("SELECT hash FROM names WHERE path = ?").get(name) as { hash: string }).hash;
  } finally {
    db.close();
  }
}

used by