postgres

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RelationTuplesTable   = "relation_tuples"
	SchemaDefinitionTable = "schema_definitions"
	TransactionsTable     = "transactions"
	TenantsTable          = "tenants"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GarbageCollector

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

GarbageCollector - Structure for GarbageCollector

func NewGarbageCollector

func NewGarbageCollector(ctx context.Context, db *db.Postgres, logger logger.Interface, cfg config.DatabaseGarbageCollection) *GarbageCollector

NewGarbageCollector creates a new GarbageCollector instance. ctx: context for managing goroutines and cancellation concurrencyLimit: the maximum number of concurrent garbage collection

func (*GarbageCollector) Start

func (c *GarbageCollector) Start() error

Start begins processing permission check requests from the RequestChan. It starts an errgroup that manages multiple goroutines for garbage collector check.

func (*GarbageCollector) Stop

func (c *GarbageCollector) Stop()

Stop stops input by closing the GarbageCollector.

func (*GarbageCollector) Wait

func (c *GarbageCollector) Wait() error

Wait waits for all goroutines in the errgroup to finish. Returns an error if any of the goroutines encounter an error.

type RelationshipReader

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

RelationshipReader is a structure that holds information and dependencies required for reading relationship data from the database.

func NewRelationshipReader

func NewRelationshipReader(database *db.Postgres, logger logger.Interface) *RelationshipReader

NewRelationshipReader creates a new instance of the RelationshipReader struct with the given database and logger instances. It also sets the default transaction options for the RelationshipReader.

Parameters:

  • database: A pointer to a Postgres database instance, which will be used to perform operations on the relationship data.
  • logger: An instance of a logger that implements the logger.Interface, which will be used to log messages related to the operations performed by the RelationshipReader.

Returns:

  • A pointer to a new RelationshipReader instance, initialized with the given database and logger instances, and the default transaction options.

func (*RelationshipReader) HeadSnapshot

func (r *RelationshipReader) HeadSnapshot(ctx context.Context, tenantID string) (token.SnapToken, error)

HeadSnapshot retrieves the latest snapshot token for a given tenant ID. It queries the transaction table to find the highest transaction ID associated with the tenant.

Parameters: - ctx: The context used for tracing and cancellation. - tenantID: The tenant ID for which the latest snapshot token should be retrieved.

Returns: - token.SnapToken: The latest snapshot token associated with the tenant. - error: An error, if any occurred during the execution of the query.

func (*RelationshipReader) QueryRelationships

func (r *RelationshipReader) QueryRelationships(ctx context.Context, tenantID string, filter *base.TupleFilter, snap string) (it *database.TupleIterator, err error)

QueryRelationships retrieves relationships from the database based on a given filter, tenant ID, and snapshot value. It returns a TupleIterator containing the filtered results.

Parameters:

  • ctx: The context used for tracing and cancellation.
  • tenantID: The tenant ID for which the relationships should be queried.
  • filter: A pointer to a TupleFilter struct that defines the filtering criteria for the relationships query.
  • snap: A string representing the snapshot value to be used for the query.

Returns: - it: A pointer to a TupleIterator containing the filtered relationships. - err: An error, if any occurred during the execution of the query.

func (*RelationshipReader) ReadRelationships

func (r *RelationshipReader) ReadRelationships(ctx context.Context, tenantID string, filter *base.TupleFilter, snap string, pagination database.Pagination) (collection *database.TupleCollection, ct database.EncodedContinuousToken, err error)

ReadRelationships retrieves relationships from the database based on a given filter, tenant ID, snapshot value, and pagination settings. It returns a TupleCollection containing the filtered results and an encoded continuous token for pagination.

Parameters:

  • ctx: The context used for tracing and cancellation.
  • tenantID: The tenant ID for which the relationships should be queried.
  • filter: A pointer to a TupleFilter struct that defines the filtering criteria for the relationships query.
  • snap: A string representing the snapshot value to be used for the query.
  • pagination: A Pagination struct containing the page size and token for the query.

Returns: - collection: A pointer to a TupleCollection containing the filtered relationships. - ct: An EncodedContinuousToken representing the next token for pagination. - err: An error, if any occurred during the execution of the query.

type RelationshipWriter

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

RelationshipWriter - Structure for Relationship Writer

func NewRelationshipWriter

func NewRelationshipWriter(database *db.Postgres, logger logger.Interface) *RelationshipWriter

NewRelationshipWriter - Creates a new RelationTupleReader

func (*RelationshipWriter) DeleteRelationships

func (w *RelationshipWriter) DeleteRelationships(ctx context.Context, tenantID string, filter *base.TupleFilter) (token token.EncodedSnapToken, err error)

DeleteRelationships - Deletes a collection of relationships to the database

func (*RelationshipWriter) WriteRelationships

func (w *RelationshipWriter) WriteRelationships(ctx context.Context, tenantID string, collection *database.TupleCollection) (token token.EncodedSnapToken, err error)

WriteRelationships - Writes a collection of relationships to the database

type SchemaReader

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

SchemaReader - Structure for SchemaReader

func NewSchemaReader

func NewSchemaReader(database *db.Postgres, logger logger.Interface) *SchemaReader

NewSchemaReader - Creates a new SchemaReader

func (*SchemaReader) HeadVersion

func (r *SchemaReader) HeadVersion(ctx context.Context, tenantID string) (version string, err error)

HeadVersion - Finds the latest version of the schema.

func (*SchemaReader) ReadSchema

func (r *SchemaReader) ReadSchema(ctx context.Context, tenantID, version string) (sch *base.SchemaDefinition, err error)

ReadSchema - Reads entity config from the repository.

func (*SchemaReader) ReadSchemaDefinition

func (r *SchemaReader) ReadSchemaDefinition(ctx context.Context, tenantID, entityType, version string) (definition *base.EntityDefinition, v string, err error)

ReadSchemaDefinition - Reads entity config from the repository.

type SchemaWriter

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

SchemaWriter - Structure for SchemaWriter

func NewSchemaWriter

func NewSchemaWriter(database *db.Postgres, logger logger.Interface) *SchemaWriter

NewSchemaWriter creates a new SchemaWriter

func (*SchemaWriter) WriteSchema

func (w *SchemaWriter) WriteSchema(ctx context.Context, schemas []storage.SchemaDefinition) (err error)

WriteSchema writes a schema to the database

type TenantReader

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

func NewTenantReader

func NewTenantReader(database *db.Postgres, logger logger.Interface) *TenantReader

NewTenantReader - Creates a new TenantReader

func (*TenantReader) ListTenants

func (r *TenantReader) ListTenants(ctx context.Context, pagination database.Pagination) (tenants []*base.Tenant, ct database.EncodedContinuousToken, err error)

ListTenants - Lists all Tenants

type TenantWriter

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

TenantWriter - Structure for Tenant Writer

func NewTenantWriter

func NewTenantWriter(database *db.Postgres, logger logger.Interface) *TenantWriter

NewTenantWriter - Creates a new TenantWriter

func (*TenantWriter) CreateTenant

func (w *TenantWriter) CreateTenant(ctx context.Context, id, name string) (result *base.Tenant, err error)

CreateTenant - Creates a new Tenant

func (*TenantWriter) DeleteTenant

func (w *TenantWriter) DeleteTenant(ctx context.Context, tenantID string) (result *base.Tenant, err error)

DeleteTenant - Deletes a Tenant

type Watch added in v0.4.4

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

Watch is an implementation of the storage.Watch interface, which is used

func NewWatcher added in v0.4.4

func NewWatcher(database *db.Postgres, logger logger.Interface) *Watch

NewWatcher returns a new instance of the Watch.

func (*Watch) Watch added in v0.4.4

func (w *Watch) Watch(ctx context.Context, tenantID, snap string) (<-chan *base.TupleChanges, <-chan error)

Watch returns a channel that emits a stream of changes to the relationship tuples in the database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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