537b5cb0b3
1. **Remove duplicate staffReadAt** in `packages/db/src/schema.ts` (TS1117 duplicate identifier — merge conflict artifact) 2. **Add count to db index exports** in `packages/db/src/index.ts` (`count` from drizzle-orm was used in conversations.ts but not exported) 3. **Use dev version of conversations.ts** (no type errors, sql\`count(*)\`) — PR branch version had incompatible type errors (staff.businessId, count, optedOutAt fields not in schema) 4. **Remove duplicate conversationsRouter import** in `apps/api/src/index.ts` All 289 tests pass, 0 lint errors. Co-Authored-By: Paperclip <noreply@paperclip.ing>
21 lines
673 B
TypeScript
21 lines
673 B
TypeScript
import { drizzle } from "drizzle-orm/postgres-js";
|
|
import postgres from "postgres";
|
|
import * as schema from "./schema.js";
|
|
|
|
export * from "./schema.js";
|
|
export { encryptSecret, decryptSecret } from "./crypto.js";
|
|
export { and, asc, count, desc, eq, exists, gte, gt, ilike, inArray, isNull, lt, lte, ne, or, sql } from "drizzle-orm";
|
|
|
|
let _db: ReturnType<typeof drizzle> | null = null;
|
|
|
|
export function getDb() {
|
|
if (_db) return _db;
|
|
const url = process.env.DATABASE_URL;
|
|
if (!url) throw new Error("DATABASE_URL is not set");
|
|
const client = postgres(url, { max: 10 });
|
|
_db = drizzle(client, { schema });
|
|
return _db;
|
|
}
|
|
|
|
export type Db = ReturnType<typeof getDb>;
|