sqlcommon

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Overview

Package sqlcommon contains utility functions shared among all SQL data stores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFromUlid added in v1.8.0

func AddFromUlid(sb sq.SelectBuilder, fromUlid string, sortDescending bool) sq.SelectBuilder

func FindLatestAuthorizationModel added in v1.5.0

func FindLatestAuthorizationModel(
	ctx context.Context,
	dbInfo *DBInfo,
	store string,
) (*openfgav1.AuthorizationModel, error)

FindLatestAuthorizationModel reads the latest authorization model corresponding to the store.

func IsReady added in v1.3.4

func IsReady(ctx context.Context, db *sql.DB) (storage.ReadinessStatus, error)

IsReady returns true if the connection to the datastore is successful and the datastore has the latest migration applied.

func MarshalRelationshipCondition added in v1.6.1

func MarshalRelationshipCondition(
	rel *openfgav1.RelationshipCondition,
) (name string, context []byte, err error)

func NewSQLContinuationTokenSerializer added in v1.8.0

func NewSQLContinuationTokenSerializer() encoder.ContinuationTokenSerializer

func ReadAuthorizationModel added in v1.3.3

func ReadAuthorizationModel(
	ctx context.Context,
	dbInfo *DBInfo,
	store, modelID string,
) (*openfgav1.AuthorizationModel, error)

ReadAuthorizationModel reads the model corresponding to store and model ID.

func Write

func Write(
	ctx context.Context,
	dbInfo *DBInfo,
	store string,
	deletes storage.Deletes,
	writes storage.Writes,
	now time.Time,
) error

Write provides the common method for writing to database across sql storage.

func WriteAuthorizationModel added in v1.3.3

func WriteAuthorizationModel(
	ctx context.Context,
	dbInfo *DBInfo,
	store string,
	model *openfgav1.AuthorizationModel,
) error

WriteAuthorizationModel writes an authorization model for the given store in one row.

Types

type Config

type Config struct {
	Username               string
	Password               string
	Logger                 logger.Logger
	MaxTuplesPerWriteField int
	MaxTypesPerModelField  int

	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxIdleTime time.Duration
	ConnMaxLifetime time.Duration

	ExportMetrics bool
}

Config defines the configuration parameters for setting up and managing a sql connection.

func NewConfig

func NewConfig(opts ...DatastoreOption) *Config

NewConfig creates a new Config instance with default values and applies any provided DatastoreOption modifications.

type ContToken

type ContToken struct {
	Ulid       string `json:"ulid"`
	ObjectType string `json:"ObjectType"`
}

ContToken represents a continuation token structure used in pagination.

func NewContToken

func NewContToken(ulid, objectType string) *ContToken

NewContToken creates a new instance of ContToken with the provided ULID and object type.

type DBInfo

type DBInfo struct {
	HandleSQLError errorHandlerFn
	// contains filtered or unexported fields
}

DBInfo encapsulates DB information for use in common method.

func NewDBInfo

func NewDBInfo(db *sql.DB, stbl sq.StatementBuilderType, errorHandler errorHandlerFn, dialect string) *DBInfo

NewDBInfo constructs a DBInfo object.

type DatastoreOption

type DatastoreOption func(*Config)

DatastoreOption defines a function type used for configuring a Config object.

func WithConnMaxIdleTime

func WithConnMaxIdleTime(d time.Duration) DatastoreOption

WithConnMaxIdleTime returns a DatastoreOption that sets the maximum idle time for a connection in the Config.

func WithConnMaxLifetime

func WithConnMaxLifetime(d time.Duration) DatastoreOption

WithConnMaxLifetime returns a DatastoreOption that sets the maximum lifetime for a connection in the Config.

func WithLogger

func WithLogger(l logger.Logger) DatastoreOption

WithLogger returns a DatastoreOption that sets the Logger in the Config.

func WithMaxIdleConns

func WithMaxIdleConns(c int) DatastoreOption

WithMaxIdleConns returns a DatastoreOption that sets the maximum number of idle connections in the Config.

func WithMaxOpenConns

func WithMaxOpenConns(c int) DatastoreOption

WithMaxOpenConns returns a DatastoreOption that sets the maximum number of open connections in the Config.

func WithMaxTuplesPerWrite

func WithMaxTuplesPerWrite(maxTuples int) DatastoreOption

WithMaxTuplesPerWrite returns a DatastoreOption that sets the maximum number of tuples per write in the Config.

func WithMaxTypesPerAuthorizationModel

func WithMaxTypesPerAuthorizationModel(maxTypes int) DatastoreOption

WithMaxTypesPerAuthorizationModel returns a DatastoreOption that sets the maximum number of types per authorization model in the Config.

func WithMetrics added in v1.3.5

func WithMetrics() DatastoreOption

WithMetrics returns a DatastoreOption that enables the export of metrics in the Config.

func WithPassword added in v1.1.0

func WithPassword(password string) DatastoreOption

WithPassword returns a DatastoreOption that sets the password in the Config.

func WithUsername added in v1.1.0

func WithUsername(username string) DatastoreOption

WithUsername returns a DatastoreOption that sets the username in the Config.

type SQLContinuationTokenSerializer added in v1.8.0

type SQLContinuationTokenSerializer struct{}

func (*SQLContinuationTokenSerializer) Deserialize added in v1.8.0

func (s *SQLContinuationTokenSerializer) Deserialize(continuationToken string) (ulid string, objType string, err error)

func (*SQLContinuationTokenSerializer) Serialize added in v1.8.0

func (s *SQLContinuationTokenSerializer) Serialize(ulid string, objType string) ([]byte, error)

type SQLTupleIterator

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

SQLTupleIterator is a struct that implements the storage.TupleIterator interface for iterating over tuples fetched from a SQL database.

func NewSQLTupleIterator

func NewSQLTupleIterator(rows *sql.Rows) *SQLTupleIterator

NewSQLTupleIterator returns a SQL tuple iterator.

func (*SQLTupleIterator) Head added in v1.5.9

Head will return the first available item.

func (*SQLTupleIterator) Next

Next will return the next available item.

func (*SQLTupleIterator) Stop

func (t *SQLTupleIterator) Stop()

Stop terminates iteration.

func (*SQLTupleIterator) ToArray

ToArray converts the tupleIterator to an []*openfgav1.Tuple and a possibly empty continuation token. If the continuation token exists it is the ulid of the last element of the returned array.

Jump to

Keyboard shortcuts

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