Documentation
¶
Index ¶
- Constants
- func AfterPooledConnectionEstablished(ctx context.Context, conn *pgx.Conn) error
- func AfterPooledConnectionRelease(conn *pgx.Conn) bool
- func IsPostgreSQLGraph(db graph.Database) bool
- func NewPool(poolCfg *pgxpool.Config) (*pgxpool.Pool, error)
- func NewValueMapper(ctx context.Context, kindMapper KindMapper) graph.ValueMapper
- func OptimizedTranslationEnabled() bool
- func OptionSetQueryExecMode(queryExecMode pgx.QueryExecMode) graph.TransactionOption
- func SetOptimizedTranslation(enabled bool) bool
- type Config
- type Driver
- func (s *Driver) AssertSchema(ctx context.Context, schema graph.Schema) error
- func (s *Driver) BatchOperation(ctx context.Context, batchDelegate graph.BatchDelegate, ...) error
- func (s *Driver) Close(ctx context.Context) error
- func (s *Driver) DeleteNodesByKinds(ctx context.Context, includeAny graph.Kinds, excludeAny graph.Kinds) error
- func (s *Driver) DeleteRelationshipsByKinds(ctx context.Context, kinds graph.Kinds) error
- func (s *Driver) FetchKinds(_ context.Context) (graph.Kinds, error)
- func (s *Driver) FetchSchema(ctx context.Context) (graph.Schema, error)
- func (s *Driver) KindMapper() KindMapper
- func (s *Driver) OptimizeStorage(ctx context.Context) error
- func (s *Driver) RefreshKinds(ctx context.Context) error
- func (s *Driver) Run(ctx context.Context, query string, parameters map[string]any) error
- func (s *Driver) SetBatchWriteSize(size int)
- func (s *Driver) SetDefaultGraph(ctx context.Context, graphSchema graph.Graph) error
- func (s *Driver) SetWriteFlushSize(size int)
- func (s *Driver) TranslationCacheStats() TranslationCacheStats
- func (s *Driver) WipeGraph(ctx context.Context, retain graph.TransactionDelegate) error
- type DriverOptions
- type Int2ArrayEncoder
- type IterationOptions
- type KindMapper
- type LargeNodeUpdateRows
- type NodeUpdateParameters
- type NodeUpsertParameters
- type QueryHook
- type QueryHookOptions
- type QueryPathInspector
- type RelationshipUpdateByParameters
- func (s *RelationshipUpdateByParameters) Append(ctx context.Context, update *sql.RelationshipUpdate, ...) error
- func (s *RelationshipUpdateByParameters) AppendAll(ctx context.Context, updates *sql.RelationshipUpdateBatch, ...) error
- func (s *RelationshipUpdateByParameters) Format(graphTarget model.Graph) []any
- type SQLState
- type SchemaManager
- func NewSchemaManager(pool *pgxpool.Pool, graphQueryMemoryLimit size.Size) *SchemaManager
- func NewSchemaManagerWithOptions(pool *pgxpool.Pool, graphQueryMemoryLimit size.Size, options DriverOptions) *SchemaManager
- func NewSchemaManagerWithTranslationCache(pool *pgxpool.Pool, graphQueryMemoryLimit size.Size, ...) *SchemaManager
- func (s *SchemaManager) AssertDefaultGraph(ctx context.Context, schema graph.Graph) error
- func (s *SchemaManager) AssertGraph(tx graph.Transaction, schema graph.Graph) (model.Graph, error)
- func (s *SchemaManager) AssertKinds(ctx context.Context, kinds graph.Kinds) ([]int16, error)
- func (s *SchemaManager) AssertSchema(ctx context.Context, schema graph.Schema) error
- func (s *SchemaManager) DefaultGraph() (model.Graph, bool)
- func (s *SchemaManager) Fetch(ctx context.Context) error
- func (s *SchemaManager) GetKindIDsByKind() map[int16]graph.Kind
- func (s *SchemaManager) MapKind(ctx context.Context, kind graph.Kind) (int16, error)
- func (s *SchemaManager) MapKindID(ctx context.Context, kindID int16) (graph.Kind, error)
- func (s *SchemaManager) MapKindIDs(ctx context.Context, kindIDs []int16) (graph.Kinds, error)
- func (s *SchemaManager) MapKinds(ctx context.Context, kinds graph.Kinds) ([]int16, error)
- func (s *SchemaManager) ReadTransaction(ctx context.Context, txDelegate graph.TransactionDelegate, ...) error
- func (s *SchemaManager) SetDefaultGraph(ctx context.Context, schema graph.Graph) error
- func (s *SchemaManager) WriteTransaction(ctx context.Context, txDelegate graph.TransactionDelegate, ...) error
- type TranslationCacheStats
Constants ¶
const (
DriverName = "pg"
)
const (
LargeNodeUpdateThreshold = 1_000_000
)
Variables ¶
This section is empty.
Functions ¶
func AfterPooledConnectionEstablished ¶ added in v0.5.4
func AfterPooledConnectionRelease ¶ added in v0.5.4
func IsPostgreSQLGraph ¶
func NewValueMapper ¶
func NewValueMapper(ctx context.Context, kindMapper KindMapper) graph.ValueMapper
func OptimizedTranslationEnabled ¶ added in v0.8.0
func OptimizedTranslationEnabled() bool
OptimizedTranslationEnabled reports whether PostgreSQL Cypher translation uses optimization and the translation cache for newly started compilations.
func OptionSetQueryExecMode ¶
func OptionSetQueryExecMode(queryExecMode pgx.QueryExecMode) graph.TransactionOption
func SetOptimizedTranslation ¶ added in v0.8.0
SetOptimizedTranslation enables or disables optimized PostgreSQL Cypher translation for the current process. It returns the previous setting.
Disabling optimization bypasses the translation cache and uses the baseline translation path for calls that begin after the setting changes. Existing cached entries remain available if optimization is enabled again.
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 NewDriverWithOptions ¶ added in v0.8.0
func NewDriverWithOptions(graphQueryMemoryLimit size.Size, pool *pgxpool.Pool, options DriverOptions) *Driver
NewDriverWithOptions constructs a PostgreSQL driver with driver-wide options.
func (*Driver) AssertSchema ¶
func (*Driver) BatchOperation ¶
func (s *Driver) BatchOperation(ctx context.Context, batchDelegate graph.BatchDelegate, options ...graph.BatchOption) 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
DeleteRelationshipsByKinds performs a server-side, set-based delete of relationships whose kind_id matches any of the given kinds, using the edge_kind_index for kind filtering 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) FetchSchema ¶
func (*Driver) KindMapper ¶
func (s *Driver) KindMapper() KindMapper
func (*Driver) OptimizeStorage ¶ added in v0.6.0
func (*Driver) SetBatchWriteSize ¶
func (*Driver) SetDefaultGraph ¶
func (*Driver) SetWriteFlushSize ¶
func (*Driver) TranslationCacheStats ¶ added in v0.8.0
func (s *Driver) TranslationCacheStats() TranslationCacheStats
TranslationCacheStats returns aggregate PostgreSQL translation-cache counters. It never exposes cached query text, SQL, or parameter data.
func (*Driver) WipeGraph ¶ added in v0.7.0
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 DriverOptions ¶ added in v0.8.0
type DriverOptions struct {
TranslationCacheEntries int
}
DriverOptions configures driver-wide behavior. TranslationCacheEntries is a count, not a per-connection setting; zero disables translation caching.
func DefaultDriverOptions ¶ added in v0.8.0
func DefaultDriverOptions() DriverOptions
DefaultDriverOptions returns the driver-wide PostgreSQL settings used by NewDriver.
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
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 (s *RelationshipUpdateByParameters) Append(ctx context.Context, update *sql.RelationshipUpdate, schemaManager *SchemaManager) error
func (*RelationshipUpdateByParameters) AppendAll ¶
func (s *RelationshipUpdateByParameters) AppendAll(ctx context.Context, updates *sql.RelationshipUpdateBatch, schemaManager *SchemaManager) error
type SQLState ¶
type SQLState string
const (
StateObjectDoesNotExist SQLState = "42704"
)
func (SQLState) ErrorMatches ¶
type SchemaManager ¶
type SchemaManager struct {
// contains filtered or unexported fields
}
func NewSchemaManager ¶
func NewSchemaManager(pool *pgxpool.Pool, graphQueryMemoryLimit size.Size) *SchemaManager
func NewSchemaManagerWithOptions ¶ added in v0.8.0
func NewSchemaManagerWithOptions(pool *pgxpool.Pool, graphQueryMemoryLimit size.Size, options DriverOptions) *SchemaManager
NewSchemaManagerWithOptions constructs the shared compilation service with a bounded translation cache.
func NewSchemaManagerWithTranslationCache ¶ added in v0.8.0
func NewSchemaManagerWithTranslationCache(pool *pgxpool.Pool, graphQueryMemoryLimit size.Size, translationCacheEntries int) *SchemaManager
NewSchemaManagerWithTranslationCache permits an application to disable the compilation cache (zero), or to choose a bounded driver-wide entry capacity. Negative values disable the cache.
func (*SchemaManager) AssertDefaultGraph ¶
func (*SchemaManager) AssertGraph ¶
func (s *SchemaManager) AssertGraph(tx graph.Transaction, schema graph.Graph) (model.Graph, error)
func (*SchemaManager) AssertKinds ¶
func (*SchemaManager) AssertSchema ¶
func (*SchemaManager) DefaultGraph ¶
func (s *SchemaManager) DefaultGraph() (model.Graph, bool)
func (*SchemaManager) GetKindIDsByKind ¶
func (s *SchemaManager) GetKindIDsByKind() map[int16]graph.Kind
func (*SchemaManager) MapKindIDs ¶
func (*SchemaManager) ReadTransaction ¶
func (s *SchemaManager) ReadTransaction(ctx context.Context, txDelegate graph.TransactionDelegate, options ...graph.TransactionOption) error
func (*SchemaManager) SetDefaultGraph ¶
func (*SchemaManager) WriteTransaction ¶
func (s *SchemaManager) WriteTransaction(ctx context.Context, txDelegate graph.TransactionDelegate, options ...graph.TransactionOption) error
type TranslationCacheStats ¶ added in v0.8.0
type TranslationCacheStats struct {
Hits int64
Misses int64
Coalesced int64
Bypasses int64
Insertions int64
Evictions int64
BindingFailures int64
BuildFailures int64
UnoptimizedCompilations int64
Size int64
Capacity int
Generation uint64
}
TranslationCacheStats contains aggregate counters only. It intentionally exposes no source text, SQL, parameter names, values, or connection data.