postgres

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 26 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgres is the ready-made Postgres implementation of directory.Stores: the tables, the queries, and the embedded migrations a product runs with Migrate under a version table of the module's own.

The JSONB documents it writes keep a fixed shape (see jsonb.go) so a product that already holds these tables reads and writes the same rows. Out of scope: connection pooling and transactions across stores, which are the caller's (pass a pgx.Tx to New to share one), and any table the directory does not own.

Index

Constants

View Source
const MigrationsTable = "auth_schema_migrations"

MigrationsTable is where the module records its schema version. It is its own table so the module's numbering never collides with the product's migrations on a shared database.

Variables

This section is empty.

Functions

func Migrate

func Migrate(dsn string) error

Migrate runs the module's pending up-migrations against dsn, a postgres:// or postgresql:// URL. Running it when nothing is pending does nothing. A lock_timeout parameter in dsn bounds how long a migration waits for a table lock; one that gives up applied nothing and is left clean, so running Migrate again retries it. A clean schema at a version newer than this binary embeds is left alone, so an older binary still boots during a rolling upgrade or a rollback; that relies on the module's migrations staying backward-compatible.

func MigrateDown

func MigrateDown(dsn string, version uint) error

MigrateDown runs the module's down-migrations until the schema is at version; a schema at or below it, or never migrated, is left alone. A product whose own down-migrations drop tables that the module's later migrations change calls it first, so the next Migrate applies them again.

func MigrationFiles

func MigrationFiles() fs.FS

MigrationFiles returns the embedded migration files, for a product that fingerprints its schema, such as to key a cached test database.

func New

func New(db DB) directory.Stores

New returns the stores over db.

Types

type DB

type DB interface {
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Begin(ctx context.Context) (pgx.Tx, error)
}

DB is what the stores run statements on: a *pgxpool.Pool, a *pgx.Conn or a pgx.Tx. Begin on a transaction opens a savepoint, so a store whose write spans tables works unchanged inside the caller's transaction.

type SCIMTokens

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

SCIMTokens is the scim.TokenStore over the scim_clients table.

func NewSCIMTokens

func NewSCIMTokens(db DB) *SCIMTokens

NewSCIMTokens returns the SCIM client store over db.

func (*SCIMTokens) ClientByTokenHash

func (s *SCIMTokens) ClientByTokenHash(ctx context.Context, hash string) (*scim.Client, error)

func (*SCIMTokens) CreateClient

func (s *SCIMTokens) CreateClient(ctx context.Context, c *scim.Client) error

func (*SCIMTokens) ListClients

func (s *SCIMTokens) ListClients(ctx context.Context) ([]*scim.Client, error)

func (*SCIMTokens) MarkUsed

func (s *SCIMTokens) MarkUsed(ctx context.Context, name string, t time.Time) error

func (*SCIMTokens) RevokeClient

func (s *SCIMTokens) RevokeClient(ctx context.Context, name string) error

func (*SCIMTokens) RotateClient

func (s *SCIMTokens) RotateClient(ctx context.Context, c *scim.Client) error

Directories

Path Synopsis
internal
gen

Jump to

Keyboard shortcuts

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