pg

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 26 Imported by: 15

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func IsPostgreSQLGraph

func IsPostgreSQLGraph(db graph.Database) bool

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) 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) 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)

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