postgres

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DSN is the PostgreSQL Data Source Name
	// Example: "host=localhost user=postgres password=secret dbname=agent port=5432 sslmode=disable"
	DSN string

	// TableName is the name of the table to use for storage
	TableName string

	// MaxIdleConns is the maximum number of idle connections
	MaxIdleConns int

	// MaxOpenConns is the maximum number of open connections
	MaxOpenConns int

	// ConnMaxLifetime is the maximum lifetime of a connection
	ConnMaxLifetime time.Duration

	// LogLevel is the GORM log level
	LogLevel logger.LogLevel

	// AutoMigrate enables automatic table creation
	AutoMigrate bool
}

Config holds configuration for PostgreSQL store

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default PostgreSQL configuration

type Store

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

Store is a PostgreSQL-backed implementation of the store.Store interface.

Features:

  • JSONB storage for flexible data types
  • Efficient indexing on namespace and key
  • ACID compliance for data integrity
  • Powerful search with JSONB queries
  • Connection pooling

Suitable for:

  • Production deployments
  • Large-scale data storage
  • Complex queries
  • Distributed systems with shared database

func New

func New(config *Config) (*Store, error)

New creates a new PostgreSQL-backed store

func NewFromDB

func NewFromDB(db *gorm.DB, config *Config) (*Store, error)

NewFromDB creates a Store from an existing GORM DB

func (*Store) Clear

func (s *Store) Clear(ctx context.Context, namespace []string) error

Clear removes all values within a namespace

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, namespace []string, key string) error

Delete removes a value by namespace and key

func (*Store) Get

func (s *Store) Get(ctx context.Context, namespace []string, key string) (*store.Value, error)

Get retrieves a value by namespace and key

func (*Store) List

func (s *Store) List(ctx context.Context, namespace []string) ([]string, error)

List returns all keys within a namespace

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping tests the connection to PostgreSQL

func (*Store) Put

func (s *Store) Put(ctx context.Context, namespace []string, key string, value interface{}) error

Put stores a value with the given namespace and key

func (*Store) Search

func (s *Store) Search(ctx context.Context, namespace []string, filter map[string]interface{}) ([]*store.Value, error)

Search finds values matching the filter within a namespace

func (*Store) Size

func (s *Store) Size(ctx context.Context) (int64, error)

Size returns the total number of stored values

Jump to

Keyboard shortcuts

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