Chronicle

PostgreSQL Store

Production-ready PostgreSQL store using grove ORM with pgdriver.

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

Import

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

Constructor

db, err := grove.Open(pgdriver.Open(os.Getenv("DATABASE_URL")))
if err != nil {
    log.Fatal(err)
}

s := postgres.New(db)

Migrations

Run schema migrations before using the store. Migrations are idempotent -- safe to run on every startup:

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

Full setup with chronicle.New

import (
    "context"
    "log"
    "os"

    "github.com/xraph/grove"
    "github.com/xraph/grove/drivers/pgdriver"
    "github.com/xraph/chronicle"
    "github.com/xraph/chronicle/store"
    "github.com/xraph/chronicle/store/postgres"
)

ctx := context.Background()

db, err := grove.Open(pgdriver.Open(os.Getenv("DATABASE_URL")))
if err != nil {
    log.Fatal(err)
}

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

adapter := store.NewAdapter(s)

c, err := chronicle.New(chronicle.WithStore(adapter))

With the Forge extension

import "github.com/xraph/chronicle/extension"

ext := extension.New(
    extension.WithStore(s),
    // Migrate runs automatically on Start unless WithDisableMigrate(true)
)
app.Register(ext)

Interfaces implemented

postgres.Store satisfies:

  • audit.Store
  • stream.Store
  • verify.Store
  • erasure.Store
  • retention.Store
  • compliance.ReportStore
  • store.Store (composite)

Characteristics

AspectDetail
Drivergrove ORM + pgdriver
Migrationsgrove migrator with embedded SQL
TransactionsDatabase-level ACID
Pingdb.Ping(ctx)
CloseCaller-owned -- call db.Close()

On this page