mirror of
https://github.com/tale/headplane.git
synced 2026-08-19 09:26:18 +00:00
feat: upgrade to node 24 and drizzle
This commit is contained in:
@@ -1,28 +1,30 @@
|
||||
import { mkdir } from 'node:fs/promises';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { migrate } from 'drizzle-orm/libsql/migrator';
|
||||
import { drizzle } from 'drizzle-orm/libsql/sqlite3';
|
||||
import log from '~/utils/log';
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { dirname, resolve } from "node:path";
|
||||
|
||||
import { drizzle } from "drizzle-orm/node-sqlite";
|
||||
import { migrate } from "drizzle-orm/node-sqlite/migrator";
|
||||
|
||||
import log from "~/utils/log";
|
||||
|
||||
export async function createDbClient(path: string) {
|
||||
const realPath = resolve(path);
|
||||
try {
|
||||
await mkdir(dirname(realPath), { recursive: true });
|
||||
} catch (error) {
|
||||
log.error(
|
||||
'server',
|
||||
'Failed to create directory for database at %s: %s',
|
||||
realPath,
|
||||
error instanceof Error ? error.message : String(error),
|
||||
);
|
||||
throw new Error(`Could not create directory for database at ${realPath}`);
|
||||
}
|
||||
const realPath = resolve(path);
|
||||
try {
|
||||
await mkdir(dirname(realPath), { recursive: true });
|
||||
} catch (error) {
|
||||
log.error(
|
||||
"server",
|
||||
"Failed to create directory for database at %s: %s",
|
||||
realPath,
|
||||
error instanceof Error ? error.message : String(error),
|
||||
);
|
||||
throw new Error(`Could not create directory for database at ${realPath}`);
|
||||
}
|
||||
|
||||
// Turn the path into a URL with the file protocol
|
||||
const db = drizzle(`file://${realPath}`);
|
||||
migrate(db, {
|
||||
migrationsFolder: './drizzle',
|
||||
});
|
||||
// Turn the path into a URL with the file protocol
|
||||
const db = drizzle(`file://${realPath}`);
|
||||
migrate(db, {
|
||||
migrationsFolder: "./drizzle",
|
||||
});
|
||||
|
||||
return db;
|
||||
return db;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user