Documentation
¶
Overview ¶
Package postgres provides PostgreSQL integration for USID. It includes migrations for USID functions and sequences, and utilities for coordinating node IDs across application instances.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrConfigMismatch = errors.New("usid: database config does not match application config")
ErrConfigMismatch is returned when the database has a different USID configuration than the application is trying to use.
Functions ¶
func GenerateSQL ¶
GenerateSQL returns the SQL statements for creating USID functions and sequences. This is called by Migrate but can be used directly if you need the raw SQL.
Types ¶
type Config ¶
type Config struct {
Epoch int64 // Custom epoch in microseconds
NodeBits uint8 // Bits allocated for node ID
SeqBits uint8 // Bits allocated for sequence number
// CreateDomain creates a `usid` domain type as an alias for bigint.
// This provides type safety in your schema but may require configuration
// in ORMs and code generators like sqlc.
CreateDomain bool
}
Config holds the USID bit layout configuration for PostgreSQL migrations. This must match the configuration used in the Go application.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default USID configuration. Use this unless you've customized usid.Epoch, usid.NodeBits, or usid.SeqBits.
type DB ¶
type DB interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
DB is the interface for database operations. Satisfied by *sql.DB, *sql.Tx, and *sql.Conn. For pgx, use stdlib mode: stdlib.OpenDBFromPool(pool).