VibORM

postgres.js

Modern PostgreSQL driver using postgres.js

Installation

pnpm add postgres

Configuration

import { createClient } from "viborm/drivers/postgres";

const client = createClient({
  databaseUrl: process.env.DATABASE_URL,
  schema,
});

Options

OptionTypeDescription
clientSqlExisting postgres.js client
optionsOptionspostgres.js configuration
databaseUrlstringPostgreSQL connection URL
pgvectorbooleanEnable pgvector support
postgisbooleanEnable PostGIS support

Using Options

import { createClient } from "viborm/drivers/postgres";

const client = createClient({
  options: {
    host: "localhost",
    port: 5432,
    user: "postgres",
    password: "password",
    database: "mydb",
    max: 10,
  },
  schema,
});

Using Existing Client

import postgres from "postgres";
import { createClient } from "viborm/drivers/postgres";

const sql = postgres(process.env.DATABASE_URL);

const client = createClient({
  client: sql,
  schema,
});

With pgvector

import { createClient } from "viborm/drivers/postgres";

const client = createClient({
  databaseUrl: process.env.DATABASE_URL,
  pgvector: true,
  schema,
});

Transactions

postgres.js supports full transactions with automatic savepoints for nested transactions.

await client.$transaction(async (tx) => {
  await tx.user.create({ data: { name: "Alice" } });
  await tx.post.create({ data: { title: "Hello", authorId: "..." } });
});

Features

  • Modern async/await API
  • Automatic connection management
  • Full transaction support with savepoints
  • pgvector and PostGIS extensions
  • High performance

On this page