Nexus
1.x
Docs/Nexus/PostgreSQL
Open

Reading1 min
Updated31 Jul 2026
Sourcev1/stores/postgres.mdx

The store/postgres package implements Nexus's store.Store interface using the grove ORM with the PostgreSQL driver. It is the recommended store for production deployments.

Setup01

import (
    "github.com/xraph/grove"
    "github.com/xraph/grove/drivers/pgdriver"
    "github.com/xraph/nexus/store/postgres"
)

db, err := grove.Open(pgdriver.Open("postgres://user:pass@localhost:5432/nexus?sslmode=disable"))
if err != nil {
    log.Fatal(err)
}

s := postgres.New(db)
if err := s.Migrate(); err != nil {
    log.Fatal(err)
}

gw := nexus.New(
    nexus.WithDatabase(s),
)

Migrations02

Call s.Migrate() before first use. This creates all required tables and indexes. Migrations are idempotent -- safe to run on every startup.

Tables created: tenants, api_keys, usage_records.

Schema03

All tables include tenant scoping columns and JSONB fields for flexible metadata:

  • tenants -- id, name, enabled, config (JSONB), created_at, updated_at

  • api_keys -- id, tenant_id, name, hash, enabled, expires_at, created_at

  • usage_records -- id, tenant_id, request_id, model, provider, input_tokens, output_tokens, cost, created_at

Internals04

AspectDetail
Drivergrove ORM + pgdriver
Migrationsgrove orchestrator with programmatic migrations
TransactionsDatabase-level ACID
Pingdb.Ping(ctx)
CloseCaller-owned -- call db.Close()

When to use05

  • Production deployments requiring ACID transactions and full SQL query power.

  • Multi-process environments with connection pooling.

  • When you need advanced PostgreSQL features like JSONB indexing.