sqlcommon

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleSQLError

func HandleSQLError(err error, args ...interface{}) error

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

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
}

func NewConfig

func NewConfig(opts ...DatastoreOption) *Config

type ContToken

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

func NewContToken

func NewContToken(ulid, objectType string) *ContToken

func UnmarshallContToken

func UnmarshallContToken(from string) (*ContToken, error)

type DBInfo

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

DBInfo encapsulates DB information for use in common method

func NewDBInfo

func NewDBInfo(db *sql.DB, stbl sq.StatementBuilderType, sqlTime interface{}) *DBInfo

NewDBInfo constructs a DBInfo objet

type DatastoreOption

type DatastoreOption func(*Config)

func WithConnMaxIdleTime

func WithConnMaxIdleTime(d time.Duration) DatastoreOption

func WithConnMaxLifetime

func WithConnMaxLifetime(d time.Duration) DatastoreOption

func WithLogger

func WithLogger(l logger.Logger) DatastoreOption

func WithMaxIdleConns

func WithMaxIdleConns(c int) DatastoreOption

func WithMaxOpenConns

func WithMaxOpenConns(c int) DatastoreOption

func WithMaxTuplesPerWrite

func WithMaxTuplesPerWrite(maxTuples int) DatastoreOption

func WithMaxTypesPerAuthorizationModel

func WithMaxTypesPerAuthorizationModel(maxTypes int) DatastoreOption

func WithPassword added in v1.1.0

func WithPassword(password string) DatastoreOption

func WithUsername added in v1.1.0

func WithUsername(username string) DatastoreOption

type SQLObjectIterator

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

func NewSQLObjectIterator

func NewSQLObjectIterator(rows *sql.Rows) *SQLObjectIterator

NewSQLObjectIterator returns a tuple iterator for Postgres

func (*SQLObjectIterator) Next

func (o *SQLObjectIterator) Next() (*openfgapb.Object, error)

func (*SQLObjectIterator) Stop

func (o *SQLObjectIterator) Stop()

type SQLTupleIterator

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

func NewSQLTupleIterator

func NewSQLTupleIterator(rows *sql.Rows) *SQLTupleIterator

NewSQLTupleIterator returns a SQL tuple iterator

func (*SQLTupleIterator) Next

func (t *SQLTupleIterator) Next() (*openfgapb.Tuple, error)

func (*SQLTupleIterator) Stop

func (t *SQLTupleIterator) Stop()

func (*SQLTupleIterator) ToArray

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

type TupleRecord

type TupleRecord struct {
	Store      string
	ObjectType string
	ObjectID   string
	Relation   string
	User       string
	Ulid       string
	InsertedAt time.Time
}

func (*TupleRecord) AsTuple

func (t *TupleRecord) AsTuple() *openfgapb.Tuple

Jump to

Keyboard shortcuts

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