postgres

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package postgres provides a PostgreSQL backed NodeLog matching SQLite semantics.

Hash identity stays in trajir/nodes (RFC 8785 + SHA-256). This package only persists rows. Schema aligns with drivers/postgres and infrastructure.md.

Index

Constants

This section is empty.

Variables

View Source
var ErrSlotConflict = errors.New("postgres: slot conflict")

ErrSlotConflict is raised when a different payload already occupies the slot.

Functions

This section is empty.

Types

type NodeLog

type NodeLog struct {
	// contains filtered or unexported fields
}

NodeLog is an append only, content addressed IR log on PostgreSQL.

func OpenDB

func OpenDB(db *sql.DB) (*NodeLog, error)

OpenDB wraps an existing *sql.DB (for tests or advanced wiring). The caller owns the connection lifecycle unless Close is used after OpenDB when the NodeLog is no longer needed; OpenDB does not close the DB on error after schema setup fails on a caller owned handle.

func OpenDSN

func OpenDSN(dsn string) (*NodeLog, error)

OpenDSN opens a Postgres NodeLog from a connection string.

func OpenFromEnv

func OpenFromEnv() (*NodeLog, error)

OpenFromEnv resolves TRAJIR_DATABASE_URL or DATABASE_URL and opens a log.

func (*NodeLog) Append

func (l *NodeLog) Append(
	kind string,
	stepN *int,
	payload map[string]any,
	trajectoryID, tenantID string,
	seq int,
) (*nodes.Node, error)

Append stores a node. Same content id is ignored. Different payload at the same logical slot returns ErrSlotConflict.

func (*NodeLog) ClaimToolCall

func (l *NodeLog) ClaimToolCall(
	stepN int,
	payload map[string]any,
	trajectoryID, tenantID string,
	seq int,
) (claimed bool, err error)

ClaimToolCall claims a TOOL_CALL slot. claimed=false means lost the race.

func (*NodeLog) Close

func (l *NodeLog) Close() error

Close releases the database handle.

func (*NodeLog) Has

func (l *NodeLog) Has(trajectoryID, tenantID string, stepN int, kind string, seq *int) (bool, error)

Has reports whether a node of kind exists for trajectory and step scoped to tenantID. When seq is non nil, the match is limited to that sequence slot. tenantID must be non-empty; use HasAllTenants for cross-tenant administrative checks.

func (*NodeLog) HasAllTenants

func (l *NodeLog) HasAllTenants(trajectoryID string, stepN int, kind string, seq *int) (bool, error)

HasAllTenants reports whether a node of kind exists for trajectory and step across any tenant. This bypasses tenant isolation and is intended for administrative or diagnostic tools only.

func (*NodeLog) ListNodes

func (l *NodeLog) ListNodes(trajectoryID, tenantID string) ([]map[string]any, error)

ListNodes returns nodes for a trajectory scoped to tenantID.

func (*NodeLog) ListNodesAllTenants

func (l *NodeLog) ListNodesAllTenants(trajectoryID string) ([]map[string]any, error)

ListNodesAllTenants returns nodes for a trajectory across all tenants.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL