mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-07-16 21:33:41 +00:00
7f43932429
Backend *.test.ts files (and the test-support harness) no longer sit next to source files; they live under src/backend/tests/ mirroring the source layout. Imports rewritten accordingly; CLAUDE.md convention updated.
32 lines
871 B
TypeScript
32 lines
871 B
TypeScript
import Database from "better-sqlite3";
|
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
import * as schema from "../../../database/db/schema.js";
|
|
import type { DatabaseContext } from "../../../database/repositories/database-context.js";
|
|
|
|
export class TestSqliteDatabase {
|
|
private sqlite: Database.Database | null = null;
|
|
private context: DatabaseContext | null = null;
|
|
|
|
async connect(): Promise<DatabaseContext> {
|
|
if (this.context) return this.context;
|
|
|
|
this.sqlite = new Database(":memory:");
|
|
this.sqlite.exec("PRAGMA foreign_keys = ON");
|
|
this.context = {
|
|
dialect: "sqlite",
|
|
drizzle: drizzle(this.sqlite, { schema }),
|
|
sqlite: this.sqlite,
|
|
};
|
|
|
|
return this.context;
|
|
}
|
|
|
|
async close(): Promise<void> {
|
|
if (this.sqlite) {
|
|
this.sqlite.close();
|
|
this.sqlite = null;
|
|
this.context = null;
|
|
}
|
|
}
|
|
}
|