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.Storestream.Storeverify.Storeerasure.Storeretention.Storecompliance.ReportStorestore.Store(composite)
Characteristics
| Aspect | Detail |
|---|---|
| Driver | grove ORM + pgdriver |
| Migrations | grove migrator with embedded SQL |
| Transactions | Database-level ACID |
| Ping | db.Ping(ctx) |
| Close | Caller-owned -- call db.Close() |