Documentation ¶
Overview ¶
Package sqlcommon contains utility functions shared among all SQL data stores.
Index ¶
- func FindLatestAuthorizationModel(ctx context.Context, dbInfo *DBInfo, store string) (*openfgav1.AuthorizationModel, error)
- func HandleSQLError(err error, args ...interface{}) error
- func IsReady(ctx context.Context, db *sql.DB) (storage.ReadinessStatus, error)
- func ReadAuthorizationModel(ctx context.Context, dbInfo *DBInfo, store, modelID string) (*openfgav1.AuthorizationModel, error)
- func Write(ctx context.Context, dbInfo *DBInfo, store string, deletes storage.Deletes, ...) error
- func WriteAuthorizationModel(ctx context.Context, dbInfo *DBInfo, store string, ...) error
- type Config
- type ContToken
- type DBInfo
- type DatastoreOption
- func WithConnMaxIdleTime(d time.Duration) DatastoreOption
- func WithConnMaxLifetime(d time.Duration) DatastoreOption
- func WithLogger(l logger.Logger) DatastoreOption
- func WithMaxIdleConns(c int) DatastoreOption
- func WithMaxOpenConns(c int) DatastoreOption
- func WithMaxTuplesPerWrite(maxTuples int) DatastoreOption
- func WithMaxTypesPerAuthorizationModel(maxTypes int) DatastoreOption
- func WithMetrics() DatastoreOption
- func WithPassword(password string) DatastoreOption
- func WithUsername(username string) DatastoreOption
- type SQLTupleIterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 HandleSQLError ¶
HandleSQLError processes an SQL error and converts it into a more specific error type based on the nature of the SQL error.
func IsReady ¶ added in v1.3.4
IsReady returns true if the connection to the datastore is successful and the datastore has the latest migration applied.
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.
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 ¶
ContToken represents a continuation token structure used in pagination.
func NewContToken ¶
NewContToken creates a new instance of ContToken with the provided ULID and object type.
func UnmarshallContToken ¶
UnmarshallContToken takes a string representation of a continuation token and attempts to unmarshal it into a ContToken struct.
type DBInfo ¶
type DBInfo struct {
// contains filtered or unexported fields
}
DBInfo encapsulates DB information for use in common method.
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 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) ToArray ¶
func (t *SQLTupleIterator) ToArray( opts storage.PaginationOptions, ) ([]*openfgav1.Tuple, []byte, error)
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.