VibORM

Client API

Query and mutate data with full type safety

Client API

The VibORM client provides a fully type-safe API for database operations. All operations are inferred from your schema — no code generation required.

Creating a Client

import { createClient } from "viborm";
import { PostgresAdapter } from "viborm/adapters/postgres";
import { user, post } from "./schema";

const client = createClient({
  schema: { user, post },
  adapter: new PostgresAdapter({
    connectionString: process.env.DATABASE_URL,
  }),
});

Operations Overview

Query Operations

OperationDescriptionReturns
findManyFind multiple recordsT[]
findFirstFind first matching recordT | null
findUniqueFind by unique identifierT | null
findFirstOrThrowFind first or throwT
findUniqueOrThrowFind unique or throwT
existCheck if records existboolean

Mutation Operations

OperationDescriptionReturns
createCreate a recordT
createManyCreate multiple records{ count }
updateUpdate a recordT
updateManyUpdate multiple records{ count }
deleteDelete a recordT
deleteManyDelete multiple records{ count }
upsertCreate or updateT

Aggregate Operations

OperationDescriptionReturns
countCount recordsnumber
aggregateRun aggregations{ _count, _avg, ... }
groupByGroup and aggregateArray

Quick Examples

// Find many with filters
const users = await client.user.findMany({
  where: { role: "ADMIN" },
  orderBy: { createdAt: "desc" },
  take: 10,
});

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

// Create a record
const newUser = await client.user.create({
  data: {
    email: "alice@example.com",
    name: "Alice",
  },
});

// Update with relations
const updated = await client.user.update({
  where: { id: "user_123" },
  data: {
    name: "Alice Smith",
    posts: {
      create: { title: "New Post" },
    },
  },
  include: { posts: true },
});

// Count with filters
const count = await client.user.count({
  where: { role: "ADMIN" },
});

Type Safety

Every operation is fully typed:

// ✅ TypeScript knows the exact return type
const user = await client.user.findUnique({
  where: { id: "user_123" },
  select: { id: true, email: true },
});
// Type: { id: string; email: string } | null

// ❌ TypeScript catches invalid fields
await client.user.create({
  data: {
    email: "bob@example.com",
    invalidField: "value",  // Error!
  },
});

// ❌ TypeScript catches missing required fields
await client.user.create({
  data: {
    name: "Bob",
    // Error: 'email' is required
  },
});

Sections

On this page