pg

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 26 Imported by: 17

Documentation

Index

Constants

View Source
const (
	DriverName = "pg"
)
View Source
const (
	LargeNodeUpdateThreshold = 1_000_000
)

Variables

This section is empty.

Functions

func AfterPooledConnectionEstablished added in v0.5.4

func AfterPooledConnectionEstablished(ctx context.Context, conn *pgx.Conn) error

func AfterPooledConnectionRelease added in v0.5.4

func AfterPooledConnectionRelease(conn *pgx.Conn) bool

func IsPostgreSQLGraph

func IsPostgreSQLGraph(db graph.Database) bool

func NewPool

func NewPool(poolCfg *pgxpool.Config) (*pgxpool.Pool, error)

pgx pool config

func NewValueMapper

func NewValueMapper(ctx context.Context, kindMapper KindMapper) graph.ValueMapper

func OptionSetQueryExecMode

func OptionSetQueryExecMode(queryExecMode pgx.QueryExecMode) graph.TransactionOption

Types

type Config

type Config struct {
	Options            pgx.TxOptions
	QueryExecMode      pgx.QueryExecMode
	QueryResultFormats pgx.QueryResultFormats
	BatchWriteSize     int
}

type Driver

type Driver struct {
	*SchemaManager
	// contains filtered or unexported fields
}

func NewDriver

func NewDriver(graphQueryMemoryLimit size.Size, pool *pgxpool.Pool) *Driver

func (*Driver) AssertSchema

func (s *Driver) AssertSchema(ctx context.Context, schema graph.Schema) error

func (*Driver) BatchOperation

func (s *Driver) BatchOperation(ctx context.Context, batchDelegate graph.BatchDelegate, options ...graph.BatchOption) error

func (*Driver) Close

func (s *Driver) Close(ctx context.Context) error

func (*Driver) DeleteNodesByKinds added in v0.7.0

func (s *Driver) DeleteNodesByKinds(ctx context.Context, includeAny graph.Kinds, excludeAny graph.Kinds) error

DeleteNodesByKinds performs a server-side, set-based delete of nodes using the kind_ids GIN index instead of streaming node IDs through the application. A node is deleted when its kind_ids overlap includeAny (or, when includeAny is empty, for every node) and do not overlap excludeAny. Deleting nodes fires the delete_node_edges trigger, cascading the attached edge deletes.

includeAny is mapped to kind IDs tolerantly: include kinds that are not defined in the database map to no IDs and therefore match no nodes, so a request that targets only undefined kinds is a safe no-op rather than an accidental full delete. excludeAny is mapped fail-closed: if any exclude kind is undefined the delete is refused, because silently dropping an exclusion would widen the delete and could remove protected nodes (e.g. an unresolved MigrationData would turn a guarded wipe into an unguarded delete from node).

func (*Driver) DeleteRelationshipsByKinds added in v0.7.0

func (s *Driver) DeleteRelationshipsByKinds(ctx context.Context, kinds graph.Kinds) error

DeleteRelationshipsByKinds performs a server-side, set-based delete of relationships whose kind_id matches any of the given kinds, using the edge_kind_id_id_start_id_end_id_index covering index instead of streaming relationship IDs through the application.

kinds are mapped to kind IDs tolerantly: kinds that are not defined in the database map to no IDs. An empty kinds argument, or one that maps entirely to undefined kinds, deletes nothing rather than every relationship.

func (*Driver) FetchKinds

func (s *Driver) FetchKinds(_ context.Context) (graph.Kinds, error)

func (*Driver) FetchSchema

func (s *Driver) FetchSchema(ctx context.Context) (graph.Schema, error)

func (*Driver) KindMapper

func (s *Driver) KindMapper() KindMapper

func (*Driver) OptimizeStorage added in v0.6.0

func (s *Driver) OptimizeStorage(ctx context.Context) error

func (*Driver) RefreshKinds

func (s *Driver) RefreshKinds(ctx context.Context) error

func (*Driver) Run

func (s *Driver) Run(ctx context.Context, query string, parameters map[string]any) error

func (*Driver) SetBatchWriteSize

func (s *Driver) SetBatchWriteSize(size int)

func (*Driver) SetDefaultGraph

func (s *Driver) SetDefaultGraph(ctx context.Context, graphSchema graph.Graph) error

func (*Driver) SetWriteFlushSize

func (s *Driver) SetWriteFlushSize(size int)

func (*Driver) WipeGraph added in v0.7.0

func (s *Driver) WipeGraph(ctx context.Context, retain graph.TransactionDelegate) error

WipeGraph truncates the partitioned node and edge tables, removing every node and edge across all graphs in a single statement that bypasses the per-row edge cascade trigger. The optional retain delegate runs within the same transaction after the truncate, allowing callers to atomically recreate any data that must survive the wipe. If retain returns an error the transaction is rolled back and the graph is left untouched.

type Int2ArrayEncoder

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

func (*Int2ArrayEncoder) Encode

func (s *Int2ArrayEncoder) Encode(values []int16) string

type IterationOptions

type IterationOptions interface {
	Once()
}

type KindMapper

type KindMapper interface {
	MapKindID(ctx context.Context, kindID int16) (graph.Kind, error)
	MapKindIDs(ctx context.Context, kindIDs []int16) (graph.Kinds, error)
	MapKind(ctx context.Context, kind graph.Kind) (int16, error)
	MapKinds(ctx context.Context, kinds graph.Kinds) ([]int16, error)
	AssertKinds(ctx context.Context, kinds graph.Kinds) ([]int16, error)
}

func KindMapperFromGraphDatabase

func KindMapperFromGraphDatabase(graphDB graph.Database) (KindMapper, error)

type LargeNodeUpdateRows added in v0.4.12

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

LargeNodeUpdateRows accumulates encoded node rows for bulk loading via COPY FROM. The column order matches sql.NodeUpdateStagingColumns.

func NewLargeNodeUpdateRows added in v0.4.12

func NewLargeNodeUpdateRows(size int) *LargeNodeUpdateRows

func (*LargeNodeUpdateRows) Append added in v0.4.12

func (s *LargeNodeUpdateRows) Append(ctx context.Context, node *graph.Node, schemaManager *SchemaManager, kindIDEncoder Int2ArrayEncoder) error

func (*LargeNodeUpdateRows) AppendAll added in v0.4.12

func (s *LargeNodeUpdateRows) AppendAll(ctx context.Context, nodes []*graph.Node, schemaManager *SchemaManager, kindIDEncoder Int2ArrayEncoder) error

AppendAll encodes every node in the slice and appends its row to the accumulator.

func (*LargeNodeUpdateRows) Rows added in v0.4.12

func (s *LargeNodeUpdateRows) Rows() [][]any

type NodeUpdateParameters added in v0.4.12

type NodeUpdateParameters struct {
	NodeIDs           []graph.ID
	KindSlices        []string
	DeletedKindSlices []string
	Properties        []pgtype.JSONB
	DeletedProperties []string
}

func NewNodeUpdateParameters added in v0.4.12

func NewNodeUpdateParameters(size int) *NodeUpdateParameters

func (*NodeUpdateParameters) Append added in v0.4.12

func (s *NodeUpdateParameters) Append(ctx context.Context, node *graph.Node, schemaManager *SchemaManager, kindIDEncoder Int2ArrayEncoder) error

func (*NodeUpdateParameters) AppendAll added in v0.4.12

func (s *NodeUpdateParameters) AppendAll(ctx context.Context, nodes []*graph.Node, schemaManager *SchemaManager, kindIDEncoder Int2ArrayEncoder) error

func (*NodeUpdateParameters) Format added in v0.4.12

func (s *NodeUpdateParameters) Format() []any

type NodeUpsertParameters

type NodeUpsertParameters struct {
	IDFutures    []*sql.Future[graph.ID]
	KindIDSlices []string
	Properties   []pgtype.JSONB
}

func NewNodeUpsertParameters

func NewNodeUpsertParameters(size int) *NodeUpsertParameters

func (*NodeUpsertParameters) Append

func (s *NodeUpsertParameters) Append(ctx context.Context, update *sql.NodeUpdate, schemaManager *SchemaManager, kindIDEncoder Int2ArrayEncoder) error

func (*NodeUpsertParameters) AppendAll

func (s *NodeUpsertParameters) AppendAll(ctx context.Context, updates *sql.NodeUpdateBatch, schemaManager *SchemaManager, kindIDEncoder Int2ArrayEncoder) error

func (*NodeUpsertParameters) Format

func (s *NodeUpsertParameters) Format(graphTarget model.Graph) []any

type QueryHook

type QueryHook interface {
	OnStatementMatch(statement string) QueryHookOptions
	OnStatementRegex(re *regexp.Regexp) QueryHookOptions
}

type QueryHookOptions

type QueryHookOptions interface {
	Trace() IterationOptions
}

type QueryPathInspector

type QueryPathInspector interface {
	Hook() QueryHook
}

func Inspector

func Inspector() QueryPathInspector

type RelationshipUpdateByParameters

type RelationshipUpdateByParameters struct {
	StartIDs   []graph.ID
	EndIDs     []graph.ID
	KindIDs    []int16
	Properties []pgtype.JSONB
}

func NewRelationshipUpdateByParameters

func NewRelationshipUpdateByParameters(size int) *RelationshipUpdateByParameters

func (*RelationshipUpdateByParameters) Append

func (*RelationshipUpdateByParameters) AppendAll

func (s *RelationshipUpdateByParameters) AppendAll(ctx context.Context, updates *sql.RelationshipUpdateBatch, schemaManager *SchemaManager) error

func (*RelationshipUpdateByParameters) Format

func (s *RelationshipUpdateByParameters) Format(graphTarget model.Graph) []any

type SQLState

type SQLState string
const (
	StateObjectDoesNotExist SQLState = "42704"
)

func (SQLState) ErrorMatches

func (s SQLState) ErrorMatches(err error) bool

func (SQLState) String

func (s SQLState) String() string

type SchemaManager

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

func NewSchemaManager

func NewSchemaManager(pool *pgxpool.Pool, graphQueryMemoryLimit size.Size) *SchemaManager

func (*SchemaManager) AssertDefaultGraph

func (s *SchemaManager) AssertDefaultGraph(ctx context.Context, schema graph.Graph) error

func (*SchemaManager) AssertGraph

func (s *SchemaManager) AssertGraph(tx graph.Transaction, schema graph.Graph) (model.Graph, error)

func (*SchemaManager) AssertKinds

func (s *SchemaManager) AssertKinds(ctx context.Context, kinds graph.Kinds) ([]int16, error)

func (*SchemaManager) AssertSchema

func (s *SchemaManager) AssertSchema(ctx context.Context, schema graph.Schema) error

func (*SchemaManager) DefaultGraph

func (s *SchemaManager) DefaultGraph() (model.Graph, bool)

func (*SchemaManager) Fetch

func (s *SchemaManager) Fetch(ctx context.Context) error

func (*SchemaManager) GetKindIDsByKind

func (s *SchemaManager) GetKindIDsByKind() map[int16]graph.Kind

func (*SchemaManager) MapKind

func (s *SchemaManager) MapKind(ctx context.Context, kind graph.Kind) (int16, error)

func (*SchemaManager) MapKindID

func (s *SchemaManager) MapKindID(ctx context.Context, kindID int16) (graph.Kind, error)

func (*SchemaManager) MapKindIDs

func (s *SchemaManager) MapKindIDs(ctx context.Context, kindIDs []int16) (graph.Kinds, error)

func (*SchemaManager) MapKinds

func (s *SchemaManager) MapKinds(ctx context.Context, kinds graph.Kinds) ([]int16, error)

func (*SchemaManager) ReadTransaction

func (s *SchemaManager) ReadTransaction(ctx context.Context, txDelegate graph.TransactionDelegate, options ...graph.TransactionOption) error

func (*SchemaManager) SetDefaultGraph

func (s *SchemaManager) SetDefaultGraph(ctx context.Context, schema graph.Graph) error

func (*SchemaManager) WriteTransaction

func (s *SchemaManager) WriteTransaction(ctx context.Context, txDelegate graph.TransactionDelegate, options ...graph.TransactionOption) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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