Documentation ¶
Overview ¶
Package table 实现一个基于kv的关系型数据库的表格功能
Index ¶
- Constants
- Variables
- func DecodeRow(data []byte) ([]byte, []byte, error)
- func JoinKey(leftvalue, rightvalue []byte) []byte
- type Count
- type JoinData
- type JoinMeta
- type JoinTable
- func (join *JoinTable) GetData(primaryKey []byte) (*Row, error)
- func (join *JoinTable) GetLeft() *Table
- func (join *JoinTable) GetRight() *Table
- func (join *JoinTable) GetTable(name string) (*Table, error)
- func (join *JoinTable) ListIndex(indexName string, prefix []byte, primaryKey []byte, count, direction int32) (rows []*Row, err error)
- func (join *JoinTable) MustGetTable(name string) *Table
- func (join *JoinTable) Save() (kvs []*types.KeyValue, err error)
- type Option
- type Query
- func (query *Query) List(indexName string, data types.Message, primaryKey []byte, ...) (rows []*Row, err error)
- func (query *Query) ListIndex(indexName string, prefix []byte, primaryKey []byte, count, direction int32) (rows []*Row, err error)
- func (query *Query) ListOne(indexName string, data types.Message, primaryKey []byte) (row *Row, err error)
- type Row
- type RowMeta
- type Table
- func (table *Table) Add(data types.Message) error
- func (table *Table) Del(primaryKey []byte) error
- func (table *Table) DelRow(data types.Message) error
- func (table *Table) GetData(primaryKey []byte) (*Row, error)
- func (table *Table) GetMeta() RowMeta
- func (table *Table) GetQuery(kvdb db.KVDB) *Query
- func (table *Table) ListIndex(indexName string, prefix []byte, primaryKey []byte, count, direction int32) (rows []*Row, err error)
- func (table *Table) Replace(data types.Message) error
- func (table *Table) Save() (kvs []*types.KeyValue, err error)
- func (table *Table) Update(primaryKey []byte, newdata types.Message) (err error)
Constants ¶
const ( None = iota Add Update Del )
表关联设计 指出是 添加 还是 删除 行 primary key auto 的del 需要指定 primary key
Variables ¶
var ( ErrEmptyPrimaryKey = errors.New("ErrEmptyPrimaryKey") ErrPrimaryKey = errors.New("ErrPrimaryKey") ErrIndexKey = errors.New("ErrIndexKey") ErrTooManyIndex = errors.New("ErrTooManyIndex") ErrTablePrefixOrTableName = errors.New("ErrTablePrefixOrTableName") ErrDupPrimaryKey = errors.New("ErrDupPrimaryKey") ErrNilValue = errors.New("ErrNilValue") )
table 中的错误处理
Functions ¶
Types ¶
type JoinMeta ¶
type JoinMeta struct {
// contains filtered or unexported fields
}
JoinMeta left right 合成的一个meta 结构
type JoinTable ¶
JoinTable 是由两个表格组合成的一个表格,自动维护一个联合结构 其中主表: LeftTable 连接表: RightTable
func NewJoinTable ¶
NewJoinTable 新建一个JoinTable
func (*JoinTable) ListIndex ¶
func (join *JoinTable) ListIndex(indexName string, prefix []byte, primaryKey []byte, count, direction int32) (rows []*Row, err error)
ListIndex 查询jointable 数据
func (*JoinTable) MustGetTable ¶
MustGetTable if name not exist, panic
func (*JoinTable) Save ¶
Save 重写默认的save 函数,不仅仅 Save left,right table 还要save jointable 没有update 到情况,只有del, add, 性能考虑可以加上 update 的情况 目前update 是通过 del + add 完成 left modify: del index, add new index (query right by primary) (check in cache) right modify: query all primary in left, include in cache, del index, add new index TODO: 没有修改过的数据不需要修改
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query 列表查询结构
func (*Query) List ¶
func (query *Query) List(indexName string, data types.Message, primaryKey []byte, count, direction int32) (rows []*Row, err error)
List 通过某个数据,查询
type Row ¶
type Row struct { Ty int Primary []byte Data types.Message // contains filtered or unexported fields }
Row 行操作
type RowMeta ¶
type RowMeta interface { CreateRow() *Row SetPayload(types.Message) error Get(key string) ([]byte, error) }
RowMeta 定义行的操作
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table 定一个表格, 并且添加 primary key, index key