Documentation
¶
Index ¶
- type Config
- type PostgresOption
- func WithAutoMigrate(enabled bool) PostgresOption
- func WithConnMaxIdleTime(d time.Duration) PostgresOption
- func WithConnMaxLifetime(d time.Duration) PostgresOption
- func WithLogLevel(level logger.LogLevel) PostgresOption
- func WithMaxIdleConns(n int) PostgresOption
- func WithMaxOpenConns(n int) PostgresOption
- func WithTableName(tableName string) PostgresOption
- type Store
- func (s *Store) Clear(ctx context.Context, namespace []string) error
- func (s *Store) Close() error
- func (s *Store) Delete(ctx context.Context, namespace []string, key string) error
- func (s *Store) Get(ctx context.Context, namespace []string, key string) (*store.Value, error)
- func (s *Store) List(ctx context.Context, namespace []string) ([]string, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) Put(ctx context.Context, namespace []string, key string, value interface{}) error
- func (s *Store) Search(ctx context.Context, namespace []string, filter map[string]interface{}) ([]*store.Value, error)
- func (s *Store) Size(ctx context.Context) (int64, error)
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
// ConnMaxIdleTime is the maximum amount of time a connection may be idle
ConnMaxIdleTime 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 ApplyPostgresOptions ¶ added in v0.2.0
func ApplyPostgresOptions(config *Config, opts ...PostgresOption) *Config
ApplyPostgresOptions 应用选项到配置
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default PostgreSQL configuration
type PostgresOption ¶ added in v0.2.0
type PostgresOption func(*Config)
PostgresOption 定义 PostgreSQL Store 配置选项
func WithAutoMigrate ¶ added in v0.2.0
func WithAutoMigrate(enabled bool) PostgresOption
WithAutoMigrate 设置是否自动迁移
func WithConnMaxIdleTime ¶ added in v0.6.0
func WithConnMaxIdleTime(d time.Duration) PostgresOption
WithConnMaxIdleTime 设置空闲连接超时时间
func WithConnMaxLifetime ¶ added in v0.2.0
func WithConnMaxLifetime(d time.Duration) PostgresOption
WithConnMaxLifetime 设置连接最大生命周期
func WithLogLevel ¶ added in v0.2.0
func WithLogLevel(level logger.LogLevel) PostgresOption
WithLogLevel 设置 GORM 日志级别
func WithMaxIdleConns ¶ added in v0.2.0
func WithMaxIdleConns(n int) PostgresOption
WithMaxIdleConns 设置最大空闲连接数
func WithMaxOpenConns ¶ added in v0.2.0
func WithMaxOpenConns(n int) PostgresOption
WithMaxOpenConns 设置最大打开连接数
func WithTableName ¶ added in v0.2.0
func WithTableName(tableName string) PostgresOption
WithTableName 设置表名
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(dsn string, opts ...PostgresOption) (*Store, error)
New creates a new PostgreSQL-backed store with options
Example:
store, err := postgres.New("host=localhost user=postgres dbname=mydb",
postgres.WithMaxOpenConns(50),
postgres.WithAutoMigrate(true),
)
Click to show internal directories.
Click to hide internal directories.