Files
publisher-dashboard/packages/db
igm b085a315be Add transactions to auth procedures and extract DB models
- Wrap multiple DB operations in transactions for atomicity:
  - login-if-completed: device upsert + session + login_request deletion
  - forgot-password: delete old tokens + insert new token
  - signup: session + email_verification creation

- Extract reusable DB model operations to packages/db/src/models/:
  - sessions.ts: insertSession()
  - user-devices.ts: upsertUserDevice(), isDeviceTrusted()

- Update session.ts to use new model functions from @reviq/db
- Fix type narrowing in admin.test.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 15:52:05 +08:00
..
2026-01-12 13:59:34 +08:00

@reviq/db

Database client and helper functions for the RevIQ platform.

Usage

import { createDb } from "@reviq/db";

const db = createDb(process.env.DATABASE_URL);

// Use db with Kysely queries
const users = await db.selectFrom("users").selectAll().execute();

// Clean up when done
await db.destroy();

Exports

Client

  • createDb(url) - Create a Kysely database instance

Helper Functions

  • executeBootstrap(trx, input) - Bootstrap a new database with superuser and org
  • generateToken() - Generate an API token
  • hashToken(token) - Hash a token for storage
  • parseToken(token) - Parse and validate a token
  • TOKEN_PREFIX - The reviq_ prefix for API tokens

Types

  • Database - Re-exported from @reviq/db-schema
  • BootstrapInput / BootstrapResult - Types for bootstrap operation