postgres

package
v1.11.5 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 32 Imported by: 3

Documentation

Overview

Package postgres contains an implementation of the storage interface that works with Postgres.

Index

Constants

This section is empty.

Variables

View Source
var ErrInsecurePassfilePermissions = errors.New("passfile permissions are too permissive")
View Source
var ErrNoPassfile = errors.New("passfile does not exist")

Functions

func HandleSQLError added in v1.6.2

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

HandleSQLError processes an SQL error and converts it into a more specific error type based on the nature of the SQL error.

Types

type Datastore added in v1.6.2

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

Datastore provides a PostgreSQL based implementation of storage.OpenFGADatastore.

func New

func New(uri string, cfg *sqlcommon.Config) (*Datastore, error)

New creates a new Datastore storage.

func NewWithDB added in v1.6.0

func NewWithDB(primaryDB, secondaryDB *pgxpool.Pool, cfg *sqlcommon.Config) (*Datastore, error)

NewWithDB creates a new Datastore storage with the provided database connection.

func (*Datastore) Close added in v1.6.2

func (s *Datastore) Close()

Close see storage.OpenFGADatastore.Close.

func (*Datastore) CreateStore added in v1.6.2

func (s *Datastore) CreateStore(ctx context.Context, store *openfgav1.Store) (*openfgav1.Store, error)

CreateStore adds a new store to storage.

func (*Datastore) DeleteStore added in v1.6.2

func (s *Datastore) DeleteStore(ctx context.Context, id string) error

DeleteStore removes a store from storage.

func (*Datastore) FindLatestAuthorizationModel added in v1.6.2

func (s *Datastore) FindLatestAuthorizationModel(ctx context.Context, store string) (*openfgav1.AuthorizationModel, error)

FindLatestAuthorizationModel see storage.AuthorizationModelReadBackend.FindLatestAuthorizationModel.

func (*Datastore) GetStore added in v1.6.2

func (s *Datastore) GetStore(ctx context.Context, id string) (*openfgav1.Store, error)

GetStore retrieves the details of a specific store using its storeID.

func (*Datastore) IsReady added in v1.6.2

IsReady see sqlcommon.IsReady.

func (*Datastore) ListStores added in v1.6.2

func (s *Datastore) ListStores(ctx context.Context, options storage.ListStoresOptions) ([]*openfgav1.Store, string, error)

ListStores provides a paginated list of all stores present in the storage.

func (*Datastore) MaxTuplesPerWrite added in v1.6.2

func (s *Datastore) MaxTuplesPerWrite() int

MaxTuplesPerWrite see storage.RelationshipTupleWriter.MaxTuplesPerWrite.

func (*Datastore) MaxTypesPerAuthorizationModel added in v1.6.2

func (s *Datastore) MaxTypesPerAuthorizationModel() int

MaxTypesPerAuthorizationModel see storage.TypeDefinitionWriteBackend.MaxTypesPerAuthorizationModel.

func (*Datastore) Read added in v1.6.2

func (s *Datastore) Read(
	ctx context.Context,
	store string,
	filter storage.ReadFilter,
	options storage.ReadOptions,
) (storage.TupleIterator, error)

Read see storage.RelationshipTupleReader.Read.

func (*Datastore) ReadAssertions added in v1.6.2

func (s *Datastore) ReadAssertions(ctx context.Context, store, modelID string) ([]*openfgav1.Assertion, error)

ReadAssertions see storage.AssertionsBackend.ReadAssertions.

func (*Datastore) ReadAuthorizationModel added in v1.6.2

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

ReadAuthorizationModel see storage.AuthorizationModelReadBackend.ReadAuthorizationModel.

func (*Datastore) ReadAuthorizationModels added in v1.6.2

func (s *Datastore) ReadAuthorizationModels(ctx context.Context, store string, options storage.ReadAuthorizationModelsOptions) ([]*openfgav1.AuthorizationModel, string, error)

ReadAuthorizationModels see storage.AuthorizationModelReadBackend.ReadAuthorizationModels.

func (*Datastore) ReadChanges added in v1.6.2

ReadChanges see storage.ChangelogBackend.ReadChanges.

func (*Datastore) ReadPage added in v1.6.2

func (s *Datastore) ReadPage(ctx context.Context, store string, filter storage.ReadFilter, options storage.ReadPageOptions) ([]*openfgav1.Tuple, string, error)

ReadPage see storage.RelationshipTupleReader.ReadPage.

func (*Datastore) ReadStartingWithUser added in v1.6.2

ReadStartingWithUser see storage.RelationshipTupleReader.ReadStartingWithUser.

func (*Datastore) ReadUserTuple added in v1.6.2

func (s *Datastore) ReadUserTuple(ctx context.Context, store string, filter storage.ReadUserTupleFilter, options storage.ReadUserTupleOptions) (*openfgav1.Tuple, error)

ReadUserTuple see storage.RelationshipTupleReader.ReadUserTuple.

func (*Datastore) ReadUsersetTuples added in v1.6.2

ReadUsersetTuples see storage.RelationshipTupleReader.ReadUsersetTuples.

func (*Datastore) Write added in v1.6.2

func (s *Datastore) Write(
	ctx context.Context,
	store string,
	deletes storage.Deletes,
	writes storage.Writes,
	opts ...storage.TupleWriteOption,
) error

Write see storage.RelationshipTupleWriter.Write.

func (*Datastore) WriteAssertions added in v1.6.2

func (s *Datastore) WriteAssertions(ctx context.Context, store, modelID string, assertions []*openfgav1.Assertion) error

WriteAssertions see storage.AssertionsBackend.WriteAssertions.

func (*Datastore) WriteAuthorizationModel added in v1.6.2

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

WriteAuthorizationModel see storage.TypeDefinitionWriteBackend.WriteAuthorizationModel.

type FSPassfileProvider added in v1.11.5

type FSPassfileProvider struct {
	Logger     logger.Logger
	GetHomeDir func() (string, error)
	OpenFile   func(name string) (FileStat, error)
}

func (*FSPassfileProvider) OpenPassfile added in v1.11.5

func (p *FSPassfileProvider) OpenPassfile() (io.ReadCloser, error)

type FileStat added in v1.11.5

type FileStat interface {
	io.ReadCloser
	Stat() (os.FileInfo, error)
}

func FileOpener added in v1.11.5

func FileOpener(name string) (FileStat, error)

Thin wrapper around os.Open to allow mocking in tests.

type PassfileProvider added in v1.11.5

type PassfileProvider interface {
	OpenPassfile() (io.ReadCloser, error)
}

type PgxExec added in v1.10.4

type PgxExec interface {
	Exec(ctx context.Context, sql string, arguments ...any) (commandTag pgconn.CommandTag, err error)
}

PgxExec interface allows pgx Exec functionality.

type PgxQuery added in v1.10.4

type PgxQuery interface {
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
}

PgxQuery interface allows Query that returns pgx.Rows.

type PgxTxnIterQuery added in v1.10.4

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

PgxTxnIterQuery is a helper to run queries using pgxpool when used in sqlcommon iterator.

func NewPgxTxnGetRows added in v1.10.4

func NewPgxTxnGetRows(txn PgxQuery, sb SQLBuilder) (*PgxTxnIterQuery, error)

NewPgxTxnGetRows creates a PgxTxnIterQuery which allows the GetRows functionality via the specified PgxQuery txn.

func (*PgxTxnIterQuery) GetRows added in v1.10.4

func (p *PgxTxnIterQuery) GetRows(ctx context.Context) (sqlcommon.Rows, error)

GetRows executes the txn query and returns the sqlcommon.Rows.

type SQLBuilder added in v1.11.1

type SQLBuilder interface {
	ToSql() (string, []interface{}, error)
}

SQLBuilder represents any SQL statement builder that can generate SQL strings with parameterized arguments.

Jump to

Keyboard shortcuts

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