VibORM
Queries

Query Operations

Find and retrieve data from your database

Query Operations

Query operations retrieve data from your database with full type safety.

Overview

OperationDescriptionReturns
findManyFind multiple recordsT[]
findFirstFind first matchingT | null
findUniqueFind by unique IDT | null
findFirstOrThrowFind first or throwT
findUniqueOrThrowFind unique or throwT
existCheck existenceboolean

Common Options

All query operations support:

{
  where: { ... },           // Filter conditions
  select: { ... },          // Select specific fields
  include: { ... },         // Include relations
}

findMany and findFirst additionally support:

{
  orderBy: { ... },         // Sort results
  take: 10,                 // Limit results
  skip: 0,                  // Offset results
  cursor: { ... },          // Cursor pagination
  distinct: ["field"],      // Distinct values
}

Quick Examples

// Find all active users
const users = await client.user.findMany({
  where: { active: true },
});

// Find first admin
const admin = await client.user.findFirst({
  where: { role: "ADMIN" },
});

// Find by ID
const user = await client.user.findUnique({
  where: { id: "user_123" },
});

// Check if admin exists
const hasAdmin = await client.user.exist({
  where: { role: "ADMIN" },
});

Pages

On this page