engine

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

设计原则是当前最简单快捷开发,不考虑通用性和将来扩展要求。 除了需要排序的主键和索引需要转换为[]byte外,其他所有字段值,皆转换为字符串存储

Index

Constants

View Source
const (
	// SysPrefix 系统前缀
	SysPrefix = "sys"
	// 键类型常量
	KeyTypeTable = "table"
	KeyTypeIndex = "idx"
	KeyTypeField = "field"
	// Separator 键分隔符
	Separator = "-"
)

常量定义

View Source
const (
	// IDMaxLimit ID的最大限制(1字节最多能创建255个ID)
	IDMaxLimit = 255
)

常量定义

View Source
const SPLIT = util.SPLIT //分隔符

Variables

View Source
var (
	//没有主键
	ErrNoPrimaryKey = errors.New("no primary key")
	//没有记录
	ErrNoUpdateFields = errors.New("no update fields")
)
View Source
var GlobalBatchInsertImplPool = &BatchInsertImplPool{
	pool: sync.Pool{
		New: func() interface{} {
			return &BatchInsertImpl{}
		},
	},
}

全局 BatchInsertImpl 对象池

View Source
var GlobalDeleteImplPool = &DeleteImplPool{
	pool: sync.Pool{
		New: func() interface{} {
			return &DeleteImpl{}
		},
	},
}

全局 DeleteImpl 对象池

View Source
var GlobalInsertImplPool = &InsertImplPool{
	pool: sync.Pool{
		New: func() interface{} {
			return &InsertImpl{}
		},
	},
}

全局 InsertImpl 对象池

View Source
var GlobalUpdateImplPool = &UpdateImplPool{
	pool: sync.Pool{
		New: func() interface{} {
			return &UpdateImpl{}
		},
	},
}

全局 UpdateImpl 对象池

Functions

func ClearAllCaches

func ClearAllCaches()

ClearAllCaches 清除所有缓存

func ClearFieldsBytesCache

func ClearFieldsBytesCache()

ClearFieldsBytesCache 清除字段转换缓存

func ClearIndexMatchCache

func ClearIndexMatchCache()

ClearIndexMatchCache 清除索引匹配缓存

func CombineBytes

func CombineBytes(arrays [][][]byte, sep []byte, prefix []byte) [][]byte

全文索引算法 CombineBytes 接收多个字节数组,使用指定分隔符返回第一个数组与其他数组的所有可能拼接组合 返回的结果是从对象池获取的,外部调用者使用后需要通过 PutBytesArray 归还到对象池

func DisableFieldsBytesLRUCache

func DisableFieldsBytesLRUCache()

DisableFieldsBytesLRUCache 禁用 LRU 缓存

func EnableFieldsBytesLRUCache

func EnableFieldsBytesLRUCache()

EnableFieldsBytesLRUCache 启用 LRU 缓存

func GetAllCacheStats

func GetAllCacheStats() map[string]CacheStats

GetAllCacheStats 获取所有缓存统计信息

func GetAnyMap

func GetAnyMap() map[string]any

GetAnyMap 从对象池获取一个 map[string]any 对象

func GetAnyMapPointer

func GetAnyMapPointer() *map[string]any

GetAnyMapPointer 从对象池获取一个 map[string]any 并返回其指针

func GetBatchContainer

func GetBatchContainer(batch storage.Batch, indexs *Indexs, tbid uint8, kvStore storage.Store) *batchContainer

GetBatchContainer 从对象池中获取一个 batchContainer

func GetMap

func GetMap() map[any]bool

GetMap 从对象池获取一个 map[any]bool 对象 sync.Pool不会导致内存泄漏,确保返回的数据干净即可。

func GetStringSlice

func GetStringSlice() []string

GetStringSlice 从对象池获取一个 []string 切片

func Join

func Join(fieldsBytes *map[string][]byte, fields []string) []byte

系统对kv数据库优化设计,将已经存在key值索引数据,从value中略去。使用时再重新分解拼接。 所有拼接数据都要进行转义 添加匹配字段功能

func JoinAndToBytes

func JoinAndToBytes(v ...string) []byte

func MatchFields

func MatchFields(fields []string, existFields ...string) bool

前缀规则匹配索引字段

func NewBatchContainer

func NewBatchContainer(batch storage.Batch, indexs *Indexs, tbid uint8, kvStore storage.Store) *batchContainer

func PutAnyMap

func PutAnyMap(m map[string]any)

PutAnyMap 将 map[string]any 对象归还到对象池

func PutAnyMapPointer

func PutAnyMapPointer(mp *map[string]any)

PutAnyMapPointer 将 map[string]any 指针指向的对象归还到对象池

func PutBatchContainer

func PutBatchContainer(c *batchContainer)

PutBatchContainer 将 batchContainer 归还到对象池

func PutMap

func PutMap(m map[any]bool)

PutMap 将 map[any]bool 对象归还到对象池

func PutStringSlice

func PutStringSlice(s []string)

PutStringSlice 将 []string 切片归还到对象池

func ResetStringSlicePool

func ResetStringSlicePool()

ResetStringSlicePool 重置 stringSlicePool 对象池

func TableToJSON

func TableToJSON(t *Table) (string, error)

TableToJSON 将Table转换为JSON字符串

Types

type AutoInt

type AutoInt int64

func (*AutoInt) Add

func (a *AutoInt) Add(b int) int

func (*AutoInt) Decrement

func (a *AutoInt) Decrement() int

func (*AutoInt) Get

func (a *AutoInt) Get() int

func (*AutoInt) GetAndIncrementBy added in v1.9.3

func (a *AutoInt) GetAndIncrementBy(n int) int

GetAndIncrementBy 原子地获取当前值并增加指定的数量,返回增加前的值

func (*AutoInt) Increment

func (a *AutoInt) Increment() int

func (*AutoInt) IncrementBy

func (a *AutoInt) IncrementBy(n int) int

IncrementBy 批量增加指定的值,并返回增加后的值

func (*AutoInt) Reset

func (a *AutoInt) Reset()

func (*AutoInt) Set

func (a *AutoInt) Set(b int)

type BaseIndex

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

------------------------------------------ 基础索引结构体,包含所有索引类型共有的字段和方法

func (*BaseIndex) AddFields

func (bi *BaseIndex) AddFields(field ...string)

func (*BaseIndex) DeleteFields

func (bi *BaseIndex) DeleteFields(field ...string)

删除索引字段

func (*BaseIndex) GetFields

func (bi *BaseIndex) GetFields() []string

func (*BaseIndex) GetId

func (bi *BaseIndex) GetId() uint8

func (*BaseIndex) IsUnique

func (bi *BaseIndex) IsUnique(key []byte) bool

IsUnique方法返回false,表示不是唯一索引。 传入参考key=JoinValue(fieldsBytes *map[string][]byte, tbid uint8, existFields ...string) []byte

func (*BaseIndex) Join

func (bi *BaseIndex) Join(fieldsBytes *map[string][]byte) []byte

func (*BaseIndex) JoinPrefix

func (bi *BaseIndex) JoinPrefix(tbid uint8, val []byte) []byte

func (*BaseIndex) JoinValue

func (bi *BaseIndex) JoinValue(fieldsBytes *map[string][]byte, tbid uint8, existFields ...string) []byte

func (*BaseIndex) Len

func (bi *BaseIndex) Len() int

func (*BaseIndex) MatchFields

func (bi *BaseIndex) MatchFields(fields ...string) bool

func (*BaseIndex) Name

func (bi *BaseIndex) Name() string

func (*BaseIndex) Parse

func (bi *BaseIndex) Parse(primaryFields []string, pkfieldTypeLen *map[string]uint8, value []byte) (*map[string][]byte, error)

将索引的value值转换为主键map值 value=fval1+SPLIT+fval2+SPLIT+...+fieldn fields []string, value []byte, 顺序必须相同 pkfieldTypeLen,按照定长截取字段值。

func (*BaseIndex) Prefix

func (bi *BaseIndex) Prefix(tbid uint8) []byte

拼接前缀,表id+索引id

func (*BaseIndex) SetName

func (bi *BaseIndex) SetName(name string) error

基础索引的通用方法

func (*BaseIndex) UpdateFields

func (bi *BaseIndex) UpdateFields(oldfields string, newfields string)

修改索引字段名称

type BatchInsert

type BatchInsert interface {
	Insert
	// 批量插入多条记录
	BatchInsert(records []*map[string]any, batchs ...storage.Batch) ([]int, error)
	// 批量插入多条记录,不自动生成主键
	BatchInsertNoInc(batchs ...storage.Batch) ([]int, error)
	// 批量提交事务
	BatchCommit() error
}

批量插入接口

type BatchInsertImpl added in v1.9.3

type BatchInsertImpl struct {
	InsertImpl
	// contains filtered or unexported fields
}

func NewBatchInsertImpl

func NewBatchInsertImpl(table *Table, records []*map[string]any) *BatchInsertImpl

NewBatchInsertImpl 创建一个新的用于批量插入的 BatchInsertImpl 实例

func (*BatchInsertImpl) BatchCommit added in v1.9.3

func (i *BatchInsertImpl) BatchCommit() error

BatchCommit 批量提交事务

func (*BatchInsertImpl) BatchInsertInc added in v1.9.3

func (i *BatchInsertImpl) BatchInsertInc(records []*map[string]any, batchs ...storage.Batch) ([]int, error)

BatchInsertInc 批量插入多条记录,自动生成主键

func (*BatchInsertImpl) BatchInsertNoInc added in v1.9.3

func (i *BatchInsertImpl) BatchInsertNoInc(batchs ...storage.Batch) ([]int, error)

批量添加不需要自动增值的记录,并且全部记录规则相同。 可用于批量插入时序数据,当表主键为时间戳时,建议使用此方法

func (*BatchInsertImpl) Reset added in v1.9.3

func (i *BatchInsertImpl) Reset()

Reset 重置 BatchInsertImpl 实例的状态

type BatchInsertImplPool added in v1.9.3

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

BatchInsertImplPool 是 BatchInsertImpl 的对象池

func (*BatchInsertImplPool) Get added in v1.9.3

Get 从对象池中获取一个 BatchInsertImpl 实例

func (*BatchInsertImplPool) Put added in v1.9.3

func (p *BatchInsertImplPool) Put(impl *BatchInsertImpl)

Put 将 BatchInsertImpl 实例放回对象池

type CacheStats

type CacheStats struct {
	Size     int64   // 缓存大小
	Accesses int64   // 访问次数
	Hits     int64   // 命中次数
	HitRate  float64 // 命中率
}

CacheStats 缓存统计信息结构体

func GetIndexMatchCacheStats

func GetIndexMatchCacheStats() CacheStats

GetIndexMatchCacheStats 获取索引匹配缓存统计信息

type ConcurrentCache

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

ConcurrentCache 并发安全的缓存实现

func NewConcurrentCache

func NewConcurrentCache() *ConcurrentCache

NewConcurrentCache 创建新的并发缓存

func (*ConcurrentCache) Clear

func (c *ConcurrentCache) Clear()

Clear 清除缓存

func (*ConcurrentCache) Get

func (c *ConcurrentCache) Get(key string) (interface{}, bool)

Get 获取缓存条目

func (*ConcurrentCache) Set

func (c *ConcurrentCache) Set(key string, entry interface{})

Set 设置缓存条目

func (*ConcurrentCache) SetEnableStats

func (c *ConcurrentCache) SetEnableStats(enable bool)

SetEnableStats 设置是否启用统计

func (*ConcurrentCache) Size

func (c *ConcurrentCache) Size() int64

Size 获取缓存大小

func (*ConcurrentCache) Stats

func (c *ConcurrentCache) Stats() (size, accesses, hits int64)

Stats 获取缓存统计信息

type DefaultFullTextIndex

type DefaultFullTextIndex struct {
	BaseIndex // 嵌入基础索引
	// contains filtered or unexported fields
}

------------------------------------------ 默认全文索引

func DefaultFullTextIndexNew

func DefaultFullTextIndexNew(name string) (*DefaultFullTextIndex, error)

func (*DefaultFullTextIndex) JoinFullValues

func (dfi *DefaultFullTextIndex) JoinFullValues(fieldsBytes *map[string][]byte, tbid uint8, existFields ...string) [][]byte

put时拼接key的值 全文索引考据级别的切词算法。 只有全文索引才需要转义

func (*DefaultFullTextIndex) JoinValue

func (dfi *DefaultFullTextIndex) JoinValue(fieldsBytes *map[string][]byte, tbid uint8, existFields ...string) []byte

调用基类JoinValue 对应全文索引,该函数仅作搜索前缀用。 拼接全文索引前缀,所有全文索引值都会进行转义。

func (*DefaultFullTextIndex) Parse

func (dfi *DefaultFullTextIndex) Parse(primaryFields []string, pkfieldTypeLen *map[string]uint8, value []byte) (*map[string][]byte, error)

func (*DefaultFullTextIndex) SetFullField

func (dfi *DefaultFullTextIndex) SetFullField(field string, len int) error

指定那个字段是全文索引字段,以及索引长度

func (*DefaultFullTextIndex) Tokenize

func (dfi *DefaultFullTextIndex) Tokenize(nr string, ftlen int) (tokens []string)

type DefaultNormalIndex

type DefaultNormalIndex struct {
	BaseIndex // 嵌入基础索引
}

------------------------------------------ 默认普通索引,二级索引

func DefaultNormalIndexNew

func DefaultNormalIndexNew(name string) (*DefaultNormalIndex, error)

func (*DefaultNormalIndex) Tag

func (dni *DefaultNormalIndex) Tag() bool

Tag方法返回true,表示是二级索引。

type DefaultPrimaryKey

type DefaultPrimaryKey struct {
	BaseIndex // 嵌入基础索引
}

------------------------------------------ 默认主键索引 组合主键时只支持固定长度的类型的组合。 字符串类型,必须指定长度。否则无法解析或存在转义问题导致bug。

func DefaultPrimaryKeyNew

func DefaultPrimaryKeyNew(name string) (*DefaultPrimaryKey, error)

func (*DefaultPrimaryKey) GetID

func (dpk *DefaultPrimaryKey) GetID(fieldsBytes *map[string][]byte, existFields ...string) []byte

過濾存在的字段 系統設計爲過濾key存在的字段不在value中儲存。

func (*DefaultPrimaryKey) GetfieldTypeLen

func (dpk *DefaultPrimaryKey) GetfieldTypeLen(tablefields *map[string]any) *map[string]uint8

获取主键字段的总长度 组合主键时只支持固定长度的类型的组合。 字符串类型,必须指定长度。否则无法解析或存在转义问题导致bug。

func (*DefaultPrimaryKey) Parse

func (dpk *DefaultPrimaryKey) Parse(fieldsid map[uint8]string, value []byte) (*map[string][]byte, error)

// // 与func (t *Table) FormatRecord(fieldsBytes *map[string][]byte) (r []byte) 相对应 // 主键索引值记录格式:field1idvalue1-field2idvalue2-...-fieldNidvalueN // Parse(fields []string, value []byte) // fieldsid map[uint8]string // id到字段名的映射的关键作用在这里。第一个字节是字段id,后面是字段值。解析方法简单。

反格式化,解析函数,将索引的value转换为记录对应的map[string][]byte

type Delete

type Delete interface {
	// 是否提供了主键字段
	HasPrimaryKey() error
	//准备删除操作的batch
	PrepareBatch(batchs ...storage.Batch)
	// 读取要删除的记录
	ReadRecord() error
	// 删除记录
	DeleteRecord() error
	// 提交事务
	Commit() error
}

提供了一个统一的删除流程接口

type DeleteImpl

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

func NewDeleteImpl

func NewDeleteImpl(table *Table, fields *map[string]any) *DeleteImpl

NewDeleteImpl 创建一个新的 DeleteImpl 实例

func (*DeleteImpl) Commit

func (d *DeleteImpl) Commit() error

Commit 提交事务

func (*DeleteImpl) DeleteRecord added in v1.9.3

func (d *DeleteImpl) DeleteRecord() error

func (*DeleteImpl) HasPrimaryKey added in v1.9.3

func (d *DeleteImpl) HasPrimaryKey() error

func (*DeleteImpl) PrepareBatch added in v1.9.3

func (d *DeleteImpl) PrepareBatch(batchs ...storage.Batch)

func (*DeleteImpl) ReadRecord added in v1.9.3

func (d *DeleteImpl) ReadRecord() error

func (*DeleteImpl) Reset

func (d *DeleteImpl) Reset()

Reset 重置 DeleteImpl 实例的状态

type DeleteImplPool

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

DeleteImplPool 是 DeleteImpl 的对象池

func (*DeleteImplPool) Get

func (p *DeleteImplPool) Get() *DeleteImpl

Get 从对象池中获取一个 DeleteImpl 实例

func (*DeleteImplPool) Put

func (p *DeleteImplPool) Put(impl *DeleteImpl)

Put 将 DeleteImpl 实例放回对象池

type Export

type Export func(k, v []byte) bool

导出函数

type ExportRecord

type ExportRecord func(rd *record.Record) bool

导出记录 ,用于流式处理删除修改记录操作等。

type FieldsBytesPool

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

FieldsBytesPool 是用于管理 map[string][]byte 对象的池

var GlobalFieldsBytesPool *FieldsBytesPool

全局 FieldsBytesPool 实例

func NewFieldsBytesPool

func NewFieldsBytesPool() *FieldsBytesPool

NewFieldsBytesPool 创建一个新的 FieldsBytesPool

func (*FieldsBytesPool) Get

func (p *FieldsBytesPool) Get() map[string][]byte

Get 从池中获取一个 map[string][]byte 对象

func (*FieldsBytesPool) GetMapPointer

func (p *FieldsBytesPool) GetMapPointer() *map[string][]byte

GetMapPointer 从池中获取一个 map[string][]byte 并返回其指针

func (*FieldsBytesPool) Put

func (p *FieldsBytesPool) Put(m map[string][]byte)

Put 将 map[string][]byte 对象放回池中

func (*FieldsBytesPool) PutMapPointer

func (p *FieldsBytesPool) PutMapPointer(mp *map[string][]byte)

PutMapPointer 将 map[string][]byte 指针指向的对象放回池中

type FullTextIndex

type FullTextIndex interface {
	Index
	SetFullField(field string, len int) error
	//GetFtlen() int
	// 拼接全文索引值
	JoinFullValues(fieldsBytes *map[string][]byte, tbid uint8, existFields ...string) [][]byte
	// 分词方法
	Tokenize(nr string, ftlen int) (tokens []string)
	Parse(primaryFields []string, pkfieldTypeLen *map[string]uint8, value []byte) (*map[string][]byte, error)
}

------------------------------------------ 全文索引接口,嵌入基础索引接口

type IDManager

type IDManager struct {
	ValueJoiner // 嵌入值拼接器,用于生成系统ID键
	// contains filtered or unexported fields
}

IDManager 实现ID管理功能

功能描述: 1. 根据对象键(sys-table-name ,sys-tableid-idx-name,sys-tableid-field-name)读取已有ID 2. 如果对象键不存在,则从对应类型的自动增长计数器(sys-table,sys-tableid-idx,sys-tableid-field)获取新ID 3. 支持表、索引、字段等不同类型的ID管理 4. 保证线程安全

var TableIDManager *IDManager

func NewIDManager

func NewIDManager(kvStore storage.Store) *IDManager

NewIDManager 创建一个新的ID管理器

func (*IDManager) GetCurrentID

func (m *IDManager) GetCurrentID(key string) (uint8, error)

GetCurrentID 获取指定key的当前ID值(未递增)

参数: - key: 用于自动递增的key(如sys-table, sys-index等)

返回: - uint8: 当前ID值(0-255) - error: 错误信息

func (*IDManager) GetNextID

func (m *IDManager) GetNextID(key string) (uint8, error)

GetNextID 通过key值获取下一个自动递增的ID

参数: - key: 用于自动递增的key(如sys-table, sys-index等)

返回: - uint8: 生成的ID(0-255) - error: 错误信息,如ID已达上限

功能流程: 1. 从key中获取当前计数器值 2. 检查ID是否已达上限 3. 递增并存储计数器 4. 返回生成的ID

func (*IDManager) GetOrCreateID

func (m *IDManager) GetOrCreateID(key string) (uint8, bool, error)

GetOrCreateID 获取或创建基于名称和类型的ID

参数: - name: 对象名称(如表名、索引名、字段名) - objType: 对象类型前缀(table-表,idx-索引,field-字段)

返回: - uint8: 生成或获取的ID(0-255) - bool: 是否是新创建的ID - error: 错误信息,如ID已达上限

功能流程: 1. 尝试从对象key获取已存在的ID 2. 如果ID存在,直接返回 3. 如果ID不存在,从类型计数器获取当前值 4. 检查ID是否已达上限 5. 递增并存储计数器 6. 将生成的ID存储到对象key 7. 返回生成的ID bool: 是否是新创建的ID,true表示是,false表示不是

func (*IDManager) GetPreviousID

func (m *IDManager) GetPreviousID(key string) (uint8, error)

GetPreviousID 回退指定key的ID计数器,并返回回退前的ID 用于在错误时回退ID

参数: - key: 用于自动递增的key(如sys-table, sys-index等)

返回: - uint8: 回退前的ID值(0-255) - error: 错误信息,如ID已达下限(0)

func (*IDManager) ResetID

func (m *IDManager) ResetID(key string) error

ResetID 重置指定key的ID计数器为0

参数: - key: 用于自动递增的key(如sys-table, sys-index等)

返回: - error: 错误信息

func (*IDManager) SetID

func (m *IDManager) SetID(key string, id uint8) error

SetID 设置指定key的ID计数器值

参数: - key: 用于自动递增的key(如sys-table, sys-index等) - id: 要设置的ID值(0-254,因为下一次调用GetNextID会返回该值并递增)

返回: - error: 错误信息,如ID值超出范围

func (*IDManager) UpdateKey

func (m *IDManager) UpdateKey(oldKey string, newKey string) error

UpdateName 更新对象的名称,保持ID不变

参数: - oldKey: 旧的对象键(如sys-table-oldName) - newKey: 新的对象键(如sys-table-newName)

返回: - error: 错误信息,如旧键不存在

功能流程: 1. 从旧键中获取ID 2. 删除旧键 3. 将ID存储到新键 4. 返回结果

type Index

type Index interface {
	// 添加索引字段
	AddFields(field ...string)
	// 获取索引字段列表
	GetFields() []string
	Len() int

	GetId() uint8
	Name() string
	SetName(name string) error
	//修改索引字段名称
	UpdateFields(oldfields string, newfields string)
	//删除索引字段
	DeleteFields(field ...string)
	//拼接前缀,表id+索引id
	Prefix(tbid uint8) []byte
	//拼接值,字段值拼接
	Join(fieldsBytes *map[string][]byte) []byte
	//拼接前缀+值。调用Prefix方法
	JoinPrefix(tbid uint8, val []byte) []byte
	// 拼接索引前缀+索引值,调用JoinPrefix,Join方法
	JoinValue(fieldsBytes *map[string][]byte, tbid uint8, existFields ...string) []byte
	//是否唯一key,key=JoinValue方法返回的值
	IsUnique(key []byte) bool
	// 匹配索引字段
	MatchFields(fields ...string) bool
	// contains filtered or unexported methods
}

基础索引接口,定义所有索引类型共有的方法

type IndexSchema

type IndexSchema struct {
	// 索引名称
	Name string `json:"name"`

	// 索引类型:primary, normal, fulltext
	Type string `json:"type"`

	// 索引字段,顺序表示索引顺序
	Fields []string `json:"fields"`
}

type Indexs

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

索引管理结构

func NewIndexs

func NewIndexs(fields *map[string]any) *Indexs

创建索引管理实例

func (*Indexs) DeleteFields

func (i *Indexs) DeleteFields(field ...string)

删除所有包含字段的索引

func (*Indexs) DeleteIndex

func (i *Indexs) DeleteIndex(name string) error

删除索引

func (*Indexs) GetAllIndexNameIdMap

func (i *Indexs) GetAllIndexNameIdMap() map[string]uint8

获取所有索引的名称和id映射

func (*Indexs) GetAllIndexes

func (i *Indexs) GetAllIndexes() []Index

获取所有索引

func (*Indexs) GetFullTextIndexs

func (i *Indexs) GetFullTextIndexs() []FullTextIndex

返回全文索引

func (*Indexs) GetIndex

func (i *Indexs) GetIndex(name string) Index

根据名称获取索引

func (*Indexs) GetNormalIndexs

func (i *Indexs) GetNormalIndexs() []NormalIndex

返回普通索引

func (*Indexs) Len

func (i *Indexs) Len() int

获取索引数量

func (*Indexs) MatchIndex

func (i *Indexs) MatchIndex(fields ...string) Index

匹配索引,主键第一优先,其他按索引字段数量排序(字段越多,优先级越高)

func (*Indexs) UpdateFields

func (i *Indexs) UpdateFields(oldfields string, newfields string)

修改所有包含字段名称的索引

type Insert

type Insert interface {
	//检查参数
	CheckParams() error
	//准备插入操作的batch
	PrepareBatch(batchs ...storage.Batch)
	//自动增值主键
	AutoIncrement() (int, error)
	// 转换字段为字节数组
	FieldsToBytes(fields *map[string]any) *map[string][]byte
	// 格式化记录
	FormatRecord(fieldsBytes *map[string][]byte) []byte
	// 添加数据到batch
	AddRecord()
	// 提交事务
	Commit() error
}

提供了一个统一的插入流程接口 添加记录流程接口

type InsertImpl

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

func NewInsertImpl

func NewInsertImpl(table *Table, fields *map[string]any) *InsertImpl

NewInsertImpl 创建一个新的 InsertImpl 实例

func (*InsertImpl) AddRecord added in v1.9.3

func (i *InsertImpl) AddRecord()

func (*InsertImpl) AutoIncrement

func (i *InsertImpl) AutoIncrement() (int, error)

AutoIncrement 实现自动增值主键

func (*InsertImpl) CheckParams added in v1.9.3

func (i *InsertImpl) CheckParams() error

func (*InsertImpl) Commit

func (i *InsertImpl) Commit() error

Commit 提交事务

func (*InsertImpl) PrepareBatch added in v1.9.3

func (i *InsertImpl) PrepareBatch(batchs ...storage.Batch)

PrepareBatch 准备插入操作的batch

func (*InsertImpl) Reset

func (i *InsertImpl) Reset()

Reset 重置 InsertImpl 实例的状态

type InsertImplPool

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

InsertImplPool 是 InsertImpl 的对象池

func (*InsertImplPool) Get

func (p *InsertImplPool) Get() *InsertImpl

Get 从对象池中获取一个 InsertImpl 实例

func (*InsertImplPool) Put

func (p *InsertImplPool) Put(impl *InsertImpl)

Put 将 InsertImpl 实例放回对象池

type LRUCache

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

LRUCache 基于 LRU 算法的缓存实现

func GetFieldsBytesLRUCache

func GetFieldsBytesLRUCache() *LRUCache

GetFieldsBytesLRUCache 获取 LRU 缓存实例

func NewLRUCache

func NewLRUCache(capacity int) *LRUCache

NewLRUCache 创建新的 LRU 缓存

func (*LRUCache) Clear

func (c *LRUCache) Clear()

Clear 清空缓存

func (*LRUCache) Disable

func (c *LRUCache) Disable()

Disable 禁用缓存

func (*LRUCache) Enable

func (c *LRUCache) Enable()

Enable 启用缓存

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (*map[string][]byte, bool)

Get 获取缓存项

func (*LRUCache) IsEnabled

func (c *LRUCache) IsEnabled() bool

IsEnabled 检查缓存是否启用

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value *map[string][]byte)

Set 设置缓存项

func (*LRUCache) Size

func (c *LRUCache) Size() int64

Size 获取缓存大小

func (*LRUCache) Stats

func (c *LRUCache) Stats() (size, accesses, hits int64)

Stats 获取缓存统计信息

type NormalIndex

type NormalIndex interface {
	Index
	// 将索引的value转换为主键map值
	// 由于NormalIndex完全匹配index接口,所以需要一个Tag方法来区别是否是二级索引。
	Tag() bool
	Parse(primaryFields []string, pkfieldTypeLen *map[string]uint8, value []byte) (*map[string][]byte, error)
}

------------------------------------------ 普通索引接口,嵌入基础索引接口

type Page

type Page struct {
	Start int
	Count int
}

分页变量

func PageNew

func PageNew(No ...int) Page

type PrimaryKey

type PrimaryKey interface {
	Index
	// 设置主键ID
	GetID(fieldsBytes *map[string][]byte, existFields ...string) []byte
	GetfieldTypeLen(tablefields *map[string]any) *map[string]uint8
	Parse(fieldsid map[uint8]string, value []byte) (*map[string][]byte, error)
}

------------------------------------------ 主键接口,嵌入基础索引接口

type Table

type Table struct {
	TableCache
	// contains filtered or unexported fields
}

func FromSchema

func FromSchema(schema *TableSchema) (*Table, error)

FromSchema 从TableSchema创建Table 用于从元数据反序列化Table结构体

func FromSerialization

func FromSerialization(serialization *TableSerialization) (*Table, error)

FromSerialization 从TableSerialization创建Table 用于从完整序列化信息反序列化Table结构体 kvStore需要在调用此函数后重新初始化

func TableFromJSON

func TableFromJSON(jsonStr string) (*Table, error)

TableFromJSON 从JSON字符串创建Table

func TableNew

func TableNew(name string) (*Table, error)

创建或获取一个表

func (*Table) AutoValue

func (t *Table) AutoValue() int

获取自动增值的值

func (*Table) BatchFieldsToBytes

func (t *Table) BatchFieldsToBytes(records []*map[string]any) []*map[string][]byte

BatchFieldsToBytes 批量转换多个记录

func (*Table) BatchFormatRecords

func (t *Table) BatchFormatRecords(records []*map[string][]byte) [][]byte

BatchFormatRecords 批量格式化多个记录 对于批量处理场景,此方法比多次调用 FormatRecord 更高效

func (*Table) BatchInsertInc added in v1.9.3

func (t *Table) BatchInsertInc(records []*map[string]any, batchs ...storage.Batch) ([]int, error)
数据流动流程
1,外部传入 Insert(fields *map[string]any
2,// 转换字段为字节数组
fieldsBytes := t.FieldsToBytes(fields)
3,//格式化记录
record := t.FormatRecord(fieldsBytes)
4,添加更新记录
tableiter 查询功能则与上面添加的流程相反。一正一逆。

BatchInsert 批量插入多条记录 records []*map[string]any 要插入的记录列表 batchs ...storage.Batch 可选的批量操作容器 返回值:插入记录的ID列表和错误信息

func (*Table) BatchInsertNoInc

func (t *Table) BatchInsertNoInc(records []*map[string]any, batchs ...storage.Batch) ([]int, error)

BatchInsertNoInc 批量插入不需要自动增值的记录 records []*map[string]any 要插入的记录列表 batchs ...storage.Batch 可选的批量操作容器 返回值:插入记录的ID列表和错误信息 批量添加时序数据,当表主键为时间戳时,建议使用此方法

func (*Table) BatchRecordByteToAny

func (t *Table) BatchRecordByteToAny(records []*map[string][]byte) []*map[string]any

BatchRecordByteToAny 批量转换多个记录

func (*Table) CheckType

func (t *Table) CheckType(fields *map[string]any) error

检查类型是否匹配

func (*Table) CreateCompositeIndex

func (t *Table) CreateCompositeIndex(name string, fields ...string) error

创建普通复合索引

func (*Table) CreateCompositePrimaryKey

func (t *Table) CreateCompositePrimaryKey(name string, fields ...string) error

创建主键复合索引

func (*Table) CreateIndex

func (t *Table) CreateIndex(index Index) error

func (*Table) CreatePrimaryKey

func (t *Table) CreatePrimaryKey(fields ...string) error

创建主键索引(支持单个或多个字段)

func (*Table) CreateSimpleIndex

func (t *Table) CreateSimpleIndex(name string, fields ...string) error

创建普通索引(简化版,直接指定名称和字段)

func (*Table) Delete

func (t *Table) Delete(fields *map[string]any, batchs ...storage.Batch) error

删除记录 fields *map[string]any 主键值,可能是组合主键 之前Delete的缺省参数为batchs ...storage.Batch ,支持乐观锁需要增加一个参数,故而为兼容之前的函数, 使用使用 batchs ...storage.Batch 。batch和timeout合并为一个参数组数

func (*Table) DeleteAll

func (t *Table) DeleteAll() error

删除表的所有数据

func (*Table) DropIndex

func (t *Table) DropIndex(name string) error

删除指定名称的索引 删除索引不会删除现存数据,不会对数据产生影响,只是存在冗余。

func (*Table) DropPrimaryKey

func (t *Table) DropPrimaryKey() error

删除主键索引

func (*Table) ExportToCSV

func (t *Table) ExportToCSV(filePath string) error

ExportToCSV 将表数据导出为CSV格式

func (*Table) ExportToJSON

func (t *Table) ExportToJSON(filePath string) error

ExportToJSON 将表数据导出为JSON格式

func (*Table) ExportToSQL

func (t *Table) ExportToSQL(filePath string) error

ExportToSQL 将表数据导出为SQL格式

func (*Table) FieldsToBytes

func (t *Table) FieldsToBytes(fields *map[string]any) *map[string][]byte

将数据转换为字节数组,该合适添加时用。搜索时nil值不能更改 *map[string]any ==> *map[string][]byte 与RecordByteToAny相反

func (*Table) FieldsToBytesNil

func (t *Table) FieldsToBytesNil(fields *map[string]any) *map[string][]byte

将数据转换为字节数组,该合适搜索时用。搜索时nil值不能更改,否则导致结果错误

func (*Table) FieldsToBytesNilLRU

func (t *Table) FieldsToBytesNilLRU(fields *map[string]any) *map[string][]byte

FieldsToBytesNilLRU 使用 LRU 缓存的字段转换

func (*Table) For

func (t *Table) For() storage.Iterator

遍历表所有kv键值对,用于快速复制表用或删除表数据

func (*Table) ForData

func (t *Table) ForData() *TableIter

遍历表所有数据

func (*Table) FormatRecord

func (t *Table) FormatRecord(fieldsBytes *map[string][]byte) []byte

func (*Table) GetAllFieldNameIdMap

func (t *Table) GetAllFieldNameIdMap() map[string]uint8

获取所有字段名称和id映射

func (*Table) GetAllFields

func (t *Table) GetAllFields() map[string]any

获取所有字段值,用于添加记录时,直接复制,无需自行创建。

func (*Table) GetAllIndexNameIdMap

func (t *Table) GetAllIndexNameIdMap() map[string]uint8

获取所有索引的名称和id映射

func (*Table) GetAllIndexes

func (t *Table) GetAllIndexes() []Index

获取所有索引

func (*Table) GetAutoInc

func (t *Table) GetAutoInc() int

// 初始化自动增值计数器(如果需要)可能存在并发问题,需要使用锁保护

func (t *Table) initAutoCounterIfNeeded() {
	if t.counter.Get() == 0 {
		// 使用表级别的锁,避免全局锁导致的并发瓶颈
		t.initMutex.Lock()
		// 再次检查计数器是否为 0,避免重复初始化
		if t.counter.Get() == 0 {
			t.InitAuto()
		}
		t.initMutex.Unlock()
	}
}

获取自动增值的值

func (*Table) GetAutoIncBatch

func (t *Table) GetAutoIncBatch(count int) int

GetAutoIncBatch 批量获取自动增值的值 count 需要获取的ID数量 返回值:第一个ID的值

func (*Table) GetField

func (t *Table) GetField(field string) (any, bool)

获取单个字段值

func (*Table) GetFieldsName

func (t *Table) GetFieldsName() []string

获取所有字段名

func (*Table) GetId

func (t *Table) GetId() uint8

func (*Table) GetIndexByName

func (t *Table) GetIndexByName(name string) Index

根据名称获取索引

func (*Table) GetIndexesByField

func (t *Table) GetIndexesByField(field string) []Index

根据字段名获取包含该字段的所有索引

func (*Table) GetName

func (t *Table) GetName() string

GetName 获取表名

func (*Table) GetPrimary

func (t *Table) GetPrimary() []string

GetPrimary 获取主键字段名

func (*Table) GetPrimaryFields

func (t *Table) GetPrimaryFields() []string

GetPrimaryFields 获取主键字段列表(带缓存)

func (*Table) GetPrimaryKey

func (t *Table) GetPrimaryKey() PrimaryKey

获取主键索引

func (*Table) GetStore added in v1.9.3

func (t *Table) GetStore() storage.Store

GetStore 获取存储实例

func (*Table) ImportFromCSV

func (t *Table) ImportFromCSV(filePath string, batchSize int) error

ImportFromCSV 从CSV文件导入数据到表

func (*Table) ImportFromJSON

func (t *Table) ImportFromJSON(filePath string, batchSize int) error

ImportFromJSON 从JSON文件导入数据到表

func (*Table) InitAuto

func (t *Table) InitAuto()

初始化自动增值的值

func (*Table) Insert

func (t *Table) Insert(fields *map[string]any, batchs ...storage.Batch) (currentID int, err error)

插入记录

func (*Table) MatchIndex

func (t *Table) MatchIndex(fields ...string) Index

匹配索引

func (*Table) MatchIndexCached

func (t *Table) MatchIndexCached(fields []string) Index

优化后的索引匹配

func (*Table) MaxAutoValue

func (t *Table) MaxAutoValue() int

获取当前最大自动增值记录的主键值

func (*Table) RangeForAny

func (t *Table) RangeForAny(funIter storage.FunIter, Start, Limit *map[string]any) (storage.Iterator, Index, error)

区间迭代器,用于范围搜索和*TableIter的跳跃区间

func (*Table) Read

func (t *Table) Read(fields *map[string]any) ([]byte, error)

从按主键数据库读取记录

func (*Table) ReadByBytes

func (t *Table) ReadByBytes(key []byte) ([]byte, error)

// 从按主键数据库读取记录 func (t *Table) Read(fields *map[string]any) ([]byte, error) {

	// 使用 SearchImpl
	searchImpl := NewSearchImpl(t)
	// 读取记录
	record := searchImpl.Read(fields)
	if record == nil {
		GlobalSearchImplPool.Put(searchImpl)
		return nil, fmt.Errorf("主键值 '%v' 的记录不存在", fields)
	}
	// 归还对象池
	GlobalSearchImplPool.Put(searchImpl)
	return record, nil
}

从按主键数据库读取记录

func (*Table) RecordByteToAny

func (t *Table) RecordByteToAny(value *map[string][]byte) *map[string]any

*map[string][]byte ==> *map[string]any 与FieldsToBytes相反

func (*Table) ResetPrimaryFields

func (t *Table) ResetPrimaryFields()

ResetPrimaryFields 重置主键字段列表缓存

func (*Table) Search

func (t *Table) Search(fields *map[string]any, ops ...util.ComparisonOperator) (*TableIter, error)

默认ComparisonOperator是like,前缀匹配功能

func (*Table) SearchRange

func (t *Table) SearchRange(funIter storage.FunIter, Start, Limit *map[string]any) (*TableIter, error)

SearchRange 范围搜索,区间搜索 fieldname 对应索引字段名,单主键或组合主键,单索引或组合索引字段。 组合主键或索引时,Start, Limit any为最后一个字段的范围值。第一个字段必须全量匹配,也就是后缀匹配。

  1. 当Limit的最后一个字段值为nil时,表示搜索到该前缀的最大值
  2. 搜索基于索引进行,必须存在匹配的索引

该功能实现了比sql的between查询更高效强大的范围搜索

func (*Table) Searchs

func (t *Table) Searchs(funIter storage.FunIter, fields *map[string]any, ops ...util.ComparisonOperator) (*TableIter, error)

func (*Table) SetFields

func (t *Table) SetFields(fields map[string]any) error

必须先为表预设字段和类型

func (*Table) SetIndexCacheSizeLimit

func (t *Table) SetIndexCacheSizeLimit(limit int)

SetIndexCacheSizeLimit 设置索引缓存大小限制

func (*Table) ToSchema

func (t *Table) ToSchema() *TableSchema

ToSchema 将Table转换为TableSchema 用于序列化Table结构体的元数据

func (*Table) ToSerialization

func (t *Table) ToSerialization() *TableSerialization

ToSerialization 将Table转换为TableSerialization 用于完整序列化Table结构体,包括运行时状态

func (*Table) Update

func (t *Table) Update(fields *map[string]any, batchs ...storage.Batch) error

func (*Table) UpdateFieldName

func (t *Table) UpdateFieldName(oldfield string, newfield string) error

修改字段名称

type TableCache added in v1.9.3

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

缓存结构体

type TableIter

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

func TableIterNew

func TableIterNew(table *Table, iter storage.Iterator, index Index, selects ...string) *TableIter

func (*TableIter) Count

func (t *TableIter) Count() int

统计索引记录数

func (*TableIter) Delete

func (t *TableIter) Delete(limit ...int) error

删除迭代器中的记录 未来可以扩展,错误的情况下可以全部回滚或忽略。

func (*TableIter) Exist

func (t *TableIter) Exist() bool

判断是否存在指定的主键记录

func (*TableIter) ExportRecord

func (t *TableIter) ExportRecord(export ExportRecord, esc bool, limit ...int)

func (*TableIter) First

func (t *TableIter) First() bool

func (*TableIter) ForExport

func (t *TableIter) ForExport(esc bool, export Export)

遍历迭代器导出数据 export导出函数,返回false则停止导出

func (*TableIter) GetIndexFields

func (t *TableIter) GetIndexFields() []string

获取搜索时使用的索引的字段

func (*TableIter) GetIndexId

func (t *TableIter) GetIndexId() uint8

获取搜索时使用的索引的id

func (*TableIter) GetIndexName

func (t *TableIter) GetIndexName() string

获取搜索时使用的索引的名称

func (*TableIter) GetPrimaryKeys

func (t *TableIter) GetPrimaryKeys(k, v []byte, fields ...string) (r any)

提取主键值 if len(fields) == 0 ,默认是提取主键值,主键也可以是组合主键 单主键则返回原始值,组合主键则返回拼接的字符串

func (*TableIter) GetRecords

func (t *TableIter) GetRecords(esc bool, limit ...int) (r record.Records)

遍历迭代器返回解析后的记录,包含版本号字段。 用于系统内部调用,包含版本号字段。

func (*TableIter) JumpRange

func (t *TableIter) JumpRange(key []byte, jumpRanges []storage.Iterator, esc bool) []byte

// 检测跳跃区间内是否包含key // 如果包含,返回跳跃区间的结束位置 // 如果不包含,返回nil //esc true 表示顺序,false 表示倒序 场景1: 电商系统 // 商品格式:product_类别_12345 // 跳跃区间:SkipStart = []byte("product_electronics_"), SkipLimit = append([]byte("product_electronics_"), 0) // 查询除电子产品外的所有商品 场景2: 金融系统 // 交易格式:transaction_20231201_12345 // 跳跃区间:SkipStart = []byte("transaction_20231201"), SkipLimit = []byte("transaction_20231202") // 查询除2023年12月1日外的所有交易

jumpRange.First()=nil或jumpRange.Last()=nil的情况,需要特殊处理todo...(也可能不存在这样的情况)

func (*TableIter) Key

func (t *TableIter) Key() []byte

func (*TableIter) Last

func (t *TableIter) Last() bool

func (*TableIter) Map

func (t *TableIter) Map(fields ...string) (data map[any]bool)

将某字段的所有值转换为map[any]bool if len(fields) == 0 ,默认是提取主键值,否则提取指定字段值 用于与其他迭代器进行匹配。

func (*TableIter) Match

func (t *TableIter) Match(rd *map[string]any, match []match.Match) bool

// 检测记录是否符合Match条件 // 如果符合,返回true // 如果不符合,返回false 常见sql场景,f in (1,2,3) 或 and 等操作

func (*TableIter) Next

func (t *TableIter) Next() bool

func (*TableIter) ParseBytes

func (t *TableIter) ParseBytes(k, v []byte) *map[string][]byte

解析k,v里所有存在的字段byte值 主键得到整个记录值,其他索引得到主键ID值

func (*TableIter) ParseRecord

func (t *TableIter) ParseRecord(fieldsBytes *map[string][]byte) (rd record.Record)

func (*TableIter) Prev

func (t *TableIter) Prev() bool

func (*TableIter) RecordIndexTime

func (t *TableIter) RecordIndexTime(startTime time.Time, searchType string)

跟踪索引耗时

func (*TableIter) Release

func (t *TableIter) Release()

func (*TableIter) ReleaseMap

func (t *TableIter) ReleaseMap(data map[any]bool)

func (*TableIter) Seek

func (t *TableIter) Seek(key []byte) bool

Seek 移动到大于等于指定key的位置

func (*TableIter) SetJumpRanges

func (t *TableIter) SetJumpRanges(jumpRanges ...storage.Iterator)

func (*TableIter) SetMatch

func (t *TableIter) SetMatch(match ...match.Match)

func (*TableIter) SetSelects

func (t *TableIter) SetSelects(fields ...string)

sql语句中的select f0,f1,... from table 要返回的字段

func (*TableIter) Update

func (t *TableIter) Update(fields *map[string]any, limit ...int) error

更新迭代器中的记录

func (*TableIter) Valid

func (t *TableIter) Valid() bool

Valid 检查迭代器是否有效

func (*TableIter) Value

func (t *TableIter) Value() []byte

type TableIterPool

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

TableIterPool 是 TableIter 对象的池

var GlobalTableIterPool *TableIterPool

全局 TableIter 对象池实例

func NewTableIterPool

func NewTableIterPool() *TableIterPool

NewTableIterPool 创建一个新的 TableIter 对象池

func (*TableIterPool) Get

func (p *TableIterPool) Get(table *Table, iter storage.Iterator, index Index, selects ...string) *TableIter

Get 从池中获取一个干净的 TableIter 对象

func (*TableIterPool) Put

func (p *TableIterPool) Put(t *TableIter)

Put 将 TableIter 对象放回池中

type TableSchema

type TableSchema struct {
	// 表ID
	ID uint8 `json:"id"`
	// 表名
	Name string `json:"name"`

	// 字段定义,string为字段名,any为字段值示例(用于类型推断)
	Fields map[string]any `json:"fields"`

	// 字段ID映射,uint8为字段ID,string为字段名
	FieldsID map[uint8]string `json:"fields_id"`

	// 索引信息,包含所有索引的基本信息
	Indexes []IndexSchema `json:"indexes"`

	// 时间字段映射,标记字段是否为时间类型
	TimeFields map[string]bool `json:"time_fields"`

	// 主键字段列表
	PrimaryFields []string `json:"primary_fields"`
}

TableSchema 是Table结构体的映射,用于序列化和反序列化 包含Table的元数据,不包含运行时状态(如counter和kvStore)

func (*TableSchema) MarshalJSON

func (ts *TableSchema) MarshalJSON() ([]byte, error)

MarshalJSON 将TableSchema序列化为JSON

func (*TableSchema) UnmarshalJSON

func (ts *TableSchema) UnmarshalJSON(data []byte) error

UnmarshalJSON 从JSON反序列化TableSchema

type TableSerialization

type TableSerialization struct {
	// TableSchema 元数据
	Schema *TableSchema `json:"schema"`

	// 自动增值的当前值(counter AutoInt)
	CurrentAutoID int `json:"current_auto_id"`
}

func (*TableSerialization) MarshalJSON

func (ts *TableSerialization) MarshalJSON() ([]byte, error)

MarshalJSON 将TableSerialization序列化为JSON

func (*TableSerialization) UnmarshalJSON

func (ts *TableSerialization) UnmarshalJSON(data []byte) error

UnmarshalJSON 从JSON反序列化TableSerialization

type Update

type Update interface {
	//检查参数
	CheckParams() error
	//准备更新操作的batch
	PrepareBatch(batchs ...storage.Batch)
	//读取记录
	ReadRecord() error
	// 准备更新字段列表
	PrepareUpdateFields() error
	// 获取更新字段的字节表示
	GetFieldsBytes() error
	//删除旧记录
	DeleteOldRecord() error
	//添加新记录
	AddNewRecord() error
	// 提交事务
	Commit() error
}

提供了一个统一的更新流程接口

type UpdateImpl

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

func NewUpdateImpl

func NewUpdateImpl(table *Table, fields *map[string]any) *UpdateImpl

NewUpdateImpl 创建一个新的 UpdateImpl 实例

func (*UpdateImpl) AddNewRecord added in v1.9.3

func (u *UpdateImpl) AddNewRecord()

func (*UpdateImpl) CheckParams added in v1.9.3

func (u *UpdateImpl) CheckParams() error

CheckParams 检查参数是否正确

func (*UpdateImpl) Commit

func (u *UpdateImpl) Commit() error

Commit 提交事务

func (*UpdateImpl) DeleteOldRecord added in v1.9.3

func (u *UpdateImpl) DeleteOldRecord()

DeleteOldRecord 删除旧记录

func (*UpdateImpl) GetFieldsBytes added in v1.9.3

func (u *UpdateImpl) GetFieldsBytes() error

GetFieldsBytes 获取更新字段的字节表示

func (*UpdateImpl) PrepareBatch added in v1.9.3

func (u *UpdateImpl) PrepareBatch(batchs ...storage.Batch)

PrepareBatch 准备更新操作的batch

func (*UpdateImpl) PrepareUpdateFields

func (u *UpdateImpl) PrepareUpdateFields() error

PrepareUpdateFields 准备更新字段列表

func (*UpdateImpl) ReadRecord added in v1.9.3

func (u *UpdateImpl) ReadRecord() error

ReadRecord 读取记录

func (*UpdateImpl) Reset

func (u *UpdateImpl) Reset()

Reset 重置 UpdateImpl 实例的状态

type UpdateImplPool

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

UpdateImplPool 是 UpdateImpl 的对象池

func (*UpdateImplPool) Get

func (p *UpdateImplPool) Get() *UpdateImpl

Get 从对象池中获取一个 UpdateImpl 实例

func (*UpdateImplPool) Put

func (p *UpdateImplPool) Put(impl *UpdateImpl)

Put 将 UpdateImpl 实例放回对象池

type ValueJoiner

type ValueJoiner struct{}

ValueJoiner 用于实现系统ID键的生成和拼接 支持生成以下格式的键: 1. 对象键:sys-table-name, sys-tableid-idx-name, sys-tableid-field-name 2. 计数器键:sys-table, sys-tableid-idx, sys-tableid-field

func NewValueJoiner

func NewValueJoiner() *ValueJoiner

NewValueJoiner 创建一个新的值拼接器

func (*ValueJoiner) GenerateCounterKey

func (vj *ValueJoiner) GenerateCounterKey(prefix, objType string) string

GenerateCounterKey 生成计数器键 示例:sys-type

func (*ValueJoiner) GenerateFieldCounterKey

func (vj *ValueJoiner) GenerateFieldCounterKey(tableID uint8) string

GenerateFieldCounterKey 生成字段计数器键 示例:sys-tableid-field

func (*ValueJoiner) GenerateFieldKey

func (vj *ValueJoiner) GenerateFieldKey(tableID uint8, fieldName string) string

GenerateFieldKey 生成字段对象键 示例:sys-tableid-field-fieldName

func (*ValueJoiner) GenerateIndexCounterKey

func (vj *ValueJoiner) GenerateIndexCounterKey(tableID uint8) string

GenerateIndexCounterKey 生成索引计数器键 示例:sys-tableid-idx

func (*ValueJoiner) GenerateIndexKey

func (vj *ValueJoiner) GenerateIndexKey(tableID uint8, indexName string) string

GenerateIndexKey 生成索引对象键 示例:sys-tableid-idx-indexName

func (*ValueJoiner) GenerateObjectKey

func (vj *ValueJoiner) GenerateObjectKey(prefix, objType, name string) string

GenerateObjectKey 生成基本对象键 示例:sys-type-name

func (*ValueJoiner) GenerateTableCounterKey

func (vj *ValueJoiner) GenerateTableCounterKey() string

GenerateTableCounterKey 生成表计数器键 示例:sys-table

func (*ValueJoiner) GenerateTableKey

func (vj *ValueJoiner) GenerateTableKey(tableName string) string

GenerateTableKey 生成表对象键 示例:sys-table-tableName

func (*ValueJoiner) Join

func (vj *ValueJoiner) Join(parts ...string) string

Join 实现基本的值拼接功能 根据输入的参数生成拼接后的字符串

Jump to

Keyboard shortcuts

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