mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-15 17:19:40 +02:00
- Move from apps-archived/ to apps/ - Delete NestJS backend, PocketBase, old scripts and docs - Create Hono/Bun redirect server (click tracking, analytics API) - Create @manacore/uload-database shared Drizzle schema package - Add local-first store (Dexie.js) for links, tags, folders - Rewrite Links and Tags pages to use IndexedDB - Simplify hooks, layouts, remove all server-side data loading - Add dev scripts: dev:uload:web, dev:uload:server, dev:uload:local Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
import postgres from 'postgres';
|
|
import * as schema from './schema';
|
|
|
|
export * from './schema';
|
|
|
|
// Re-export drizzle operators used by the backend
|
|
export { eq, and, or, desc, sql, gte, lte, ilike } from 'drizzle-orm';
|
|
|
|
// Database instance type
|
|
export type Database = ReturnType<typeof getDb>;
|
|
|
|
// Infer types for backend services
|
|
export type Link = typeof schema.links.$inferSelect;
|
|
export type NewLink = typeof schema.links.$inferInsert;
|
|
export type Click = typeof schema.clicks.$inferSelect;
|
|
export type NewClick = typeof schema.clicks.$inferInsert;
|
|
|
|
let db: Database | null = null;
|
|
let client: ReturnType<typeof postgres> | null = null;
|
|
|
|
export function getDb(): ReturnType<typeof drizzle<typeof schema>> {
|
|
if (!db) {
|
|
const connectionString =
|
|
process.env.DATABASE_URL ||
|
|
'postgresql://uload:uload_dev_password_123@localhost:5432/uload_dev';
|
|
|
|
client = postgres(connectionString, {
|
|
max: 10,
|
|
idle_timeout: 20,
|
|
connect_timeout: 10,
|
|
});
|
|
|
|
db = drizzle(client, { schema });
|
|
}
|
|
return db!;
|
|
}
|
|
|
|
export async function closeDb(): Promise<void> {
|
|
if (client) {
|
|
await client.end();
|
|
client = null;
|
|
db = null;
|
|
}
|
|
}
|