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 OptionSetQueryExecMode(queryExecMode pgx.QueryExecMode) graph.TransactionOption
- 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) WipeGraph(ctx context.Context, retain graph.TransactionDelegate) error
- 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 (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
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 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 (*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_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) 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) 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 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 (*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