postgres

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 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 {
	Schema      string
	Table       string
	BatchConfig *batch.Config
	Writer      batch.BatchWriter
}

Config 控制 Postgres 存储行为 Config controls Postgres storage behaviour.

type Option

type Option func(*Config)

Option 是用于自定义配置的函数。 Option customises the storage configuration.

func WithBatchConfig

func WithBatchConfig(batchCfg *batch.Config) Option

WithBatchConfig 指定批量写入配置。

func WithBatchWriter

func WithBatchWriter(writer batch.BatchWriter) Option

WithBatchWriter 指定自定义批量写入器(测试用)。

func WithSchema

func WithSchema(schema string) Option

WithSchema 指定数据库 schema 名称。

func WithTable

func WithTable(table string) Option

WithTable 指定存储表名称。

type PostgresStorage

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

PostgresStorage 实现 session.Storage,支持 JSON 字段与批量导入。

func NewStorage

func NewStorage(db *sql.DB, opts ...Option) (*PostgresStorage, error)

NewStorage 创建 Postgres 存储实例。

func (*PostgresStorage) BulkUpsertSessions

func (p *PostgresStorage) BulkUpsertSessions(
	ctx context.Context,
	sessions []*session.Session,
	preserveUpdatedAt bool,
) error

BulkUpsertSessions 批量导入 Session(迁移场景)。

func (*PostgresStorage) Close

func (p *PostgresStorage) Close() error

Close 释放资源(当前仅关闭批量写入器)。

func (*PostgresStorage) Create

func (p *PostgresStorage) Create(ctx context.Context, sess *session.Session) error

Create 插入新的 Session 记录(若已存在则更新)。

func (*PostgresStorage) Delete

func (p *PostgresStorage) Delete(ctx context.Context, sessionID string) error

Delete 删除 Session。

func (*PostgresStorage) Get

func (p *PostgresStorage) Get(ctx context.Context, sessionID string) (*session.Session, error)

Get 根据 SessionID 查询记录。

func (*PostgresStorage) List

func (p *PostgresStorage) List(ctx context.Context, filters map[string]interface{}) ([]*session.Session, error)

List 查询全部 Session,支持常用过滤条件。

func (*PostgresStorage) ListByAgent

func (p *PostgresStorage) ListByAgent(ctx context.Context, agentID string) ([]*session.Session, error)

ListByAgent 查询代理下的全部 Session。

func (*PostgresStorage) ListByUser

func (p *PostgresStorage) ListByUser(ctx context.Context, userID string) ([]*session.Session, error)

ListByUser 查询用户下的 Session。

func (*PostgresStorage) Update

func (p *PostgresStorage) Update(ctx context.Context, sess *session.Session) error

Update 更新 Session(不存在则报错)。

Jump to

Keyboard shortcuts

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