db

package
v0.4.2 Latest Latest
Warning

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

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

Documentation

Overview

Package db owns cs-plane's Postgres connection and complete state-operation boundary. The DSN's search_path names the one schema cs-plane owns, so it can share a server and database with other services. A cached handle plus a state-directory file lock serialize read-modify-write cycles across processes; callers may nest a transaction inside that cycle when database changes must coordinate with protected files, and read single statements unlocked. Feature packages own every table and query. Schema DDL runs only in an empty schema; an existing one is accepted by its format marker or rejected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodePayload

func DecodePayload[T any](payload string, identity func(T) bool, what string) (T, error)

DecodePayload reads a JSON payload column and refuses one whose identity does not match its row.

func IsConstraint

func IsConstraint(err error) bool

IsConstraint reports whether err is an integrity-constraint violation such as a duplicate key.

Types

type DB

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

func Open

func Open(dsn, lockDir, schema string) (*DB, error)

Open returns the shared handle for dsn, creating the schema's tables only when it holds none yet. lockDir holds the file lock that serializes state cycles across cs-plane processes.

func (*DB) Close

func (d *DB) Close() error

func (*DB) Locked

func (d *DB) Locked(fn func(*sql.DB) error) error

Locked runs one complete state cycle under the process mutex and the cross-process directory lock.

func (*DB) Reader

func (d *DB) Reader() *sql.DB

func (*DB) Tx

func (d *DB) Tx(fn func(*sql.Tx) error) (err error)

Jump to

Keyboard shortcuts

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