mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-29 16:24:58 +00:00
23 lines
590 B
Markdown
23 lines
590 B
Markdown
# Database Query Pattern
|
|
|
|
Always use the `Database` class wrapper, never raw Prisma:
|
|
|
|
Run app commands from `frontends/nextjs/`.
|
|
|
|
```typescript
|
|
// ✅ Correct - with tenant isolation
|
|
const users = await Database.getUsers({ tenantId: user.tenantId })
|
|
await Database.setSchemas(schemas, { tenantId })
|
|
|
|
// ❌ Wrong - raw Prisma, no tenant filter
|
|
const users = await prisma.user.findMany()
|
|
```
|
|
|
|
After schema changes in `prisma/schema.prisma`:
|
|
```bash
|
|
npm run db:generate # Regenerate Prisma client
|
|
npm run db:push # Push to database
|
|
```
|
|
|
|
Key file: `frontends/nextjs/src/lib/database.ts`
|