sqlstate

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sqlstate 提供基于 ACT_GE_BYTEARRAY 的 SQL 状态存储。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LockName

func LockName(namespace string) string

LockName 返回数据库独占锁名称;快照与行仓储共用同一命名规则。 @param namespace 数据库名称 @return 锁名称

Types

type DB

type DB interface {
	// ExecContext 执行语句。
	// @param ctx 上下文
	// @param query SQL
	// @param args 参数
	// @return 结果
	// @return 错误
	ExecContext(ctx context.Context, query string, args ...any) (Result, error)
	// QueryContext 执行查询。
	// @param ctx 上下文
	// @param query SQL
	// @param args 参数
	// @return 结果集
	// @return 错误
	QueryContext(ctx context.Context, query string, args ...any) (Rows, error)
}

DB 是 SQL 执行接口,便于替换真实数据库与测试替身。

type Result

type Result interface {
	// RowsAffected 返回影响行数。
	// @return 影响行数
	// @return 错误
	RowsAffected() (int64, error)
}

Result 是 SQL 执行结果。

type Rows

type Rows interface {
	// Next 前进到下一行。
	// @return 是否有下一行
	Next() bool
	// Scan 扫描当前行。
	// @param dest 目标
	// @return 扫描错误
	Scan(dest ...any) error
	// Close 关闭结果集。
	// @return 关闭错误
	Close() error
	// Err 返回遍历错误。
	// @return 遍历错误
	Err() error
}

Rows 是查询结果集。

type SQLDB

type SQLDB struct {
	DB *sql.DB // 数据库连接
}

SQLDB 将 *sql.DB 适配为 DB 接口。

func (SQLDB) ExecContext

func (s SQLDB) ExecContext(ctx context.Context, query string, args ...any) (Result, error)

ExecContext 执行语句。 @param ctx 上下文 @param query SQL @param args 参数 @return 结果 @return 错误

func (SQLDB) QueryContext

func (s SQLDB) QueryContext(ctx context.Context, query string, args ...any) (Rows, error)

QueryContext 执行查询。 @param ctx 上下文 @param query SQL @param args 参数 @return 结果集 @return 错误

type Store

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

Store 将引擎状态快照存入 ACT_GE_BYTEARRAY。

func New

func New(db DB, dialect string) (*Store, error)

New 创建 SQL 状态存储。 @param db 数据库接口 @param dialect 数据库方言 @return 状态存储 @return 创建错误

func NewExclusiveMySQL

func NewExclusiveMySQL(ctx context.Context, db *sql.DB, namespace string) (*Store, func() error, error)

NewExclusiveMySQL 获取快照独占连接;其他进程占用时立即拒绝启动。 @param ctx 初始化上下文 @param db 数据库连接池 @param namespace 数据库名称 @return 快照存储 @return 幂等释放函数 @return 获取错误

func (*Store) CheckOwner

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

CheckOwner 在底层具备独占会话时验证其所有权。 @param ctx 上下文 @return 所有权错误

func (*Store) Load

func (s *Store) Load(ctx context.Context) ([]byte, error)

Load 读取状态。 @param ctx 上下文 @return 状态字节 @return 错误

func (*Store) Save

func (s *Store) Save(ctx context.Context, data []byte) error

Save 保存状态。 @param ctx 上下文 @param data 状态字节 @return 错误

Jump to

Keyboard shortcuts

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