feat(db): add @atomcms/db package skeleton + mysql2/drizzle client

This commit is contained in:
Simo committed 2026-06-27 14:32:45 +02:00
1 parent c2366fe6c9
commit 0966aa7dda
5 files changed
+848

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
{
"name": "@atomcms/db",
"version": "0.0.0",
"private": true,
"type": "module",
"main": "./src/index.ts",
"types": "./src/index.ts",
"scripts": {
"test": "vitest run",
"typecheck": "tsc --noEmit",
"db:pull": "drizzle-kit pull"
},
"dependencies": {
"drizzle-orm": "^0.38.0",
"mysql2": "^3.11.0"
},
"devDependencies": {
"drizzle-kit": "^0.30.0",
"typescript": "^5.7.0",
"vitest": "^2.1.0"
}
}
+16
View File
@@ -0,0 +1,16 @@
import { drizzle, type MySql2Database } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import * as schema from "./schema/index.js";
export type Database = MySql2Database<typeof schema>;
/**
* Creates a Drizzle client backed by a mysql2 pool.
* The connection targets the LIVE emulator-owned database; this layer
* only ever reads/writes data — it never runs migrations.
*/
export function createDb(databaseUrl: string): { db: Database; pool: mysql.Pool } {
const pool = mysql.createPool(databaseUrl);
const db = drizzle(pool, { schema, mode: "default" });
return { db, pool };
}
+5
View File
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": { "rootDir": "src", "outDir": "dist" },
"include": ["src"]
}
+9
View File
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";
// Local config so Vitest does not walk up into the parent Laravel repo's
// vite.config.js (this monorepo is nested inside the Laravel project).
export default defineConfig({
test: {
environment: "node",
},
});
+796
View File
File diff suppressed because it is too large. Load diff