mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-23 00:06:42 +02:00
feat(uload): rewrite to local-first + Hono architecture
- 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>
This commit is contained in:
parent
5f187705e2
commit
d847eb4115
262 changed files with 44750 additions and 2022 deletions
45
apps/uload/packages/uload-database/src/index.ts
Normal file
45
apps/uload/packages/uload-database/src/index.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue