Documentation ¶
Index ¶
- Constants
- Variables
- func BytesToFloat32(bs []byte) float32
- func BytesToFloat64(bs []byte) float64
- func BytesToInt32(bs []byte) int32
- func BytesToInt64(bs []byte) int64
- func DropDatabase(name string, meta *MetaDBSource) error
- func Float32ToBytes(f float32) []byte
- func Float64ToBytes(f float64) []byte
- func Int32ToBytes(i int32) []byte
- func Int64ToBytes(i int64) []byte
- type B2Column
- func (col *B2Column) FormatBytes(value interface{}) ([]byte, error)
- func (col *B2Column) Index(i bool) *B2Column
- func (col *B2Column) Length(l int) *B2Column
- func (col *B2Column) ParseFloat32(value []byte) (float32, bool)
- func (col *B2Column) ParseFloat64(value []byte) (float64, bool)
- func (col *B2Column) ParseInt32(value []byte) (int32, bool)
- func (col *B2Column) ParseInt64(value []byte) (int64, bool)
- func (col *B2Column) ParseMap(value []byte) (map[string]interface{}, error)
- func (col *B2Column) ParseString(value []byte) (string, bool)
- type B2Database
- func (b2db *B2Database) AddTable(table *B2Table, meta *MetaDBSource) error
- func (b2db *B2Database) Close()
- func (b2db *B2Database) GetTable(tableName string, meta *MetaDBSource) (*B2Table, error)
- func (b2db *B2Database) OpenConnection() (*B2Database, error)
- func (b2db *B2Database) RemoveTable(tableName string, meta *MetaDBSource) error
- type B2Table
- type DataType
- type MetaDBSource
Constants ¶
View Source
const ( DtInt32 = iota // int32 -> 0, and so on. DtInt64 // int64 DtFloat32 // float32 DtFloat64 // float64 DtString // string DtBytes // []byte DtTimestamp // time )
数据类型枚举
View Source
const (
METADB = "B2META"
)
元数据库名称常量
Variables ¶
View Source
var ( // B2Int32 int32结构体 B2Int32 = DataType{Dtype: DtInt32, TypeName: "int32"} // B2Int64 int64结构体 B2Int64 = DataType{Dtype: DtInt64, TypeName: "int64"} // B2Float32 float32结构体 B2Float32 = DataType{Dtype: DtFloat32, TypeName: "float32"} // B2Float64 float64结构体 B2Float64 = DataType{Dtype: DtFloat64, TypeName: "float64"} // B2String string结构体 B2String = DataType{Dtype: DtString, TypeName: "string"} // B2Bytes []byte结构体 B2Bytes = DataType{Dtype: DtBytes, TypeName: "bytes"} // B2Timestamp time结构体 B2Timestamp = DataType{Dtype: DtTimestamp, TypeName: "timestamp"} )
一些数据类型结构体定义,使用时应作为常量处理
Functions ¶
Types ¶
type B2Column ¶
type B2Column struct { // ColumnName 字段名称 ColumnName string `json:"ColumnName"` // DataType 以字符串表示数据类型 DataType string `json:"DataType"` // DataLength 字段长度 DataLength int `json:"DataLength,omitempty"` // Indexing 是否为索引字段 Indexing bool `json:"Indexing,omitempty"` // ColumnID 字段全局唯一IDtable ColumnID string `json:"ColumnID"` // IndexID 索引全局唯一ID IndexID string `json:"IndexID"` }
B2Column 字段结构体
func (*B2Column) FormatBytes ¶
FormatBytes 将一个值按照字段数据类型定义转换为一个字节数组值
func (*B2Column) ParseFloat32 ¶
ParseFloat32 将一个字节数组值按照字段定义转换为float32
func (*B2Column) ParseFloat64 ¶
ParseFloat64 将一个字节数组值按照字段定义转换为float64
func (*B2Column) ParseInt32 ¶
ParseInt32 将一个字节数组值按照字段定义转换为int32
func (*B2Column) ParseInt64 ¶
ParseInt64 将一个字节数组值按照字段定义转换为int64
type B2Database ¶
type B2Database struct { // 数据库名称 Database string `json:"Database"` // 数据库表列表 TableList []string `json:"TableList,omitempty"` // 数据库全局唯一ID,用于作为在rocksdb中的真实数据库ID DatabaseID string `json:"DatabaseID"` // rocksdb只读连接结构体 RocksDbReadConn *rdb.DB `json:"-"` // rocksdb事务连接结构体 RocksDbWriteConn *rdb.TransactionDB `json:"-"` // 创建时间 CreateTime time.Time `json:"CreateTime,omitempty"` // 打开时间 OpenTime time.Time `json:"OpenTime,omitempty"` }
B2Database babydb数据库结构体
func NewDatabase ¶
func NewDatabase(name string, meta *MetaDBSource) (*B2Database, error)
NewDatabase 创建一个新的数据库 name 数据库名称 meta 元数据库连接结构体指针
func NewDatabaseAndOpen ¶
func NewDatabaseAndOpen(name string, meta *MetaDBSource) (*B2Database, error)
NewDatabaseAndOpen 新建数据库并打开
func (*B2Database) AddTable ¶
func (b2db *B2Database) AddTable(table *B2Table, meta *MetaDBSource) error
AddTable 在数据库中添加表
func (*B2Database) GetTable ¶
func (b2db *B2Database) GetTable(tableName string, meta *MetaDBSource) (*B2Table, error)
GetTable 在元数据中获取某个数据库表META内容
func (*B2Database) OpenConnection ¶
func (b2db *B2Database) OpenConnection() (*B2Database, error)
OpenConnection 打开B2DB数据库连接
func (*B2Database) RemoveTable ¶
func (b2db *B2Database) RemoveTable(tableName string, meta *MetaDBSource) error
RemoveTable 从数据库中移除表
type B2Table ¶
type B2Table struct { // TableName 表名 TableName string `json:"TableName"` // Columns 字段列表 Columns []B2Column `json:"Columns"` // CreateTime 创建时间 CreateTime time.Time `json:"CreateTime"` // TableID 全局唯一表ID TableID string `json:"TableID"` }
B2Table 数据库表结构体
func NewTable ¶
func NewTable(name string, cols []B2Column, b2db *B2Database, meta *MetaDBSource) (*B2Table, error)
NewTable 新建一张数据库表
func (*B2Table) InsertByMap ¶
func (t *B2Table) InsertByMap(db *B2Database, values map[string]interface{}) (string, error)
InsertByMap 使用KV对向表中插入一行数据
func (*B2Table) InsertByValues ¶
func (t *B2Table) InsertByValues(db *B2Database, values ...interface{}) (string, error)
InsertByValues 向表中插入一行数据
type MetaDBSource ¶
type MetaDBSource struct { OpenTime time.Time SyncTime time.Time Mu *sync.Mutex // contains filtered or unexported fields }
MetaDBSource 元数据库连接结构体
func (*MetaDBSource) DelDatabase ¶
func (c *MetaDBSource) DelDatabase(dbname string) error
DelDatabase 在元数据库中删除数据库
func (*MetaDBSource) GetDatabase ¶
func (c *MetaDBSource) GetDatabase(dbname string) (*B2Database, error)
GetDatabase 在元数据中查找某个名称的数据库
func (*MetaDBSource) PutDatabase ¶
func (c *MetaDBSource) PutDatabase(d2db *B2Database) error
PutDatabase 将某个数据库PUT更新到元数据中
Click to show internal directories.
Click to hide internal directories.