Ugrás a fő tartalomhoz

Data Access Layer (DAL)

The DAL is the single point of contact between the application and the database. All database queries are encapsulated here.

Location

src/lib/dal/

Design Principles

  1. No direct Drizzle imports in routes or components — always go through DAL functions
  2. Functions return plain objects — no Drizzle query builders leak into application code
  3. Input validation happens at the API route level (via Zod schemas), not in the DAL
  4. Transactions are handled within DAL functions when multiple writes need to be atomic

Usage Example

// ✅ Correct — import from DAL
import { getOrderById, updateOrderStatus } from '@/lib/dal/orders';

// ❌ Wrong — never do this in routes/components
import { db } from '@/lib/db';
import { orders } from '@/lib/db/schema';

Available Modules

ModuleResponsibilities
organisations.tsCRUD for organisations, search, settings, portfolio, members
orders.tsOrder lifecycle, status transitions, payment tracking
offers.tsOffer creation, withdrawal, acceptance
requests.tsCake request creation, matching, expiry
users.tsUser profiles, authentication records
payments.tsPayment records, earnings calculations, Stripe integration
messages.tsMessage threads, read tracking
reviews.tsReview creation and retrieval