From 0685e9ece66fbcb09c9457027cf7bb2107cc0171 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 18 Oct 2026 22:02:02 +0200 Subject: refactor: inject the database into services via a constructor Pilot on the categories service: a CategoriesService class holds the Drizzle handle, and services/index.ts wires the real instance once for the server while tests build their own on an in-memory database. AppDatabase moves from groceries.ts to db/types.ts. --- src/lib/server/services/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/lib/server/services/index.ts (limited to 'src/lib/server/services/index.ts') diff --git a/src/lib/server/services/index.ts b/src/lib/server/services/index.ts new file mode 100644 index 0000000..25a05be --- /dev/null +++ b/src/lib/server/services/index.ts @@ -0,0 +1,8 @@ +import { db } from '$lib/server/db'; +import { CategoriesService } from './categories'; + +/** + * Services wired once for the running server. Tests build their own instances + * with a test database instead of importing from here. + */ +export const categoriesService = new CategoriesService(db); -- cgit v1.3