b2schema

package
v0.0.0-...-5bb49d2 Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

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

func BytesToFloat32

func BytesToFloat32(bs []byte) float32

BytesToFloat32 将一个字节数组转换为float32值

func BytesToFloat64

func BytesToFloat64(bs []byte) float64

BytesToFloat64 将一个字节数组转换为字节数组

func BytesToInt32

func BytesToInt32(bs []byte) int32

BytesToInt32 将一个字节数组转换为int32值

func BytesToInt64

func BytesToInt64(bs []byte) int64

BytesToInt64 将一个字节数组转换为int64值

func DropDatabase

func DropDatabase(name string, meta *MetaDBSource) error

DropDatabase 删除数据库

func Float32ToBytes

func Float32ToBytes(f float32) []byte

Float32ToBytes 将一个float32值转换为字节数组

func Float64ToBytes

func Float64ToBytes(f float64) []byte

Float64ToBytes 将一个float64值转换为字节数组

func Int32ToBytes

func Int32ToBytes(i int32) []byte

Int32ToBytes 将一个int32值转换为字节数组

func Int64ToBytes

func Int64ToBytes(i int64) []byte

Int64ToBytes 将一个int64值转换为字节数组

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 NewColumn

func NewColumn(name, dt string) *B2Column

NewColumn 创建一个新的字段,仅包括基本字段名称和数据类型

func (*B2Column) FormatBytes

func (col *B2Column) FormatBytes(value interface{}) ([]byte, error)

FormatBytes 将一个值按照字段数据类型定义转换为一个字节数组值

func (*B2Column) Index

func (col *B2Column) Index(i bool) *B2Column

Index 设置字段索引

func (*B2Column) Length

func (col *B2Column) Length(l int) *B2Column

Length 设置字段数据长度

func (*B2Column) ParseFloat32

func (col *B2Column) ParseFloat32(value []byte) (float32, bool)

ParseFloat32 将一个字节数组值按照字段定义转换为float32

func (*B2Column) ParseFloat64

func (col *B2Column) ParseFloat64(value []byte) (float64, bool)

ParseFloat64 将一个字节数组值按照字段定义转换为float64

func (*B2Column) ParseInt32

func (col *B2Column) ParseInt32(value []byte) (int32, bool)

ParseInt32 将一个字节数组值按照字段定义转换为int32

func (*B2Column) ParseInt64

func (col *B2Column) ParseInt64(value []byte) (int64, bool)

ParseInt64 将一个字节数组值按照字段定义转换为int64

func (*B2Column) ParseMap

func (col *B2Column) ParseMap(value []byte) (map[string]interface{}, error)

ParseMap 将一个字节数组值按照字段定义转换为一个map

func (*B2Column) ParseString

func (col *B2Column) ParseString(value []byte) (string, bool)

ParseString 将一个字节数组值按照字段定义转换为string

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) Close

func (b2db *B2Database) Close()

Close 关闭数据库连接

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 DataType

type DataType struct {
	Dtype    int    // 数据类型枚举值
	TypeName string // 数据类型名称
}

DataType 数据类型结构体

func DtAsType

func DtAsType(dataType int) (*DataType, error)

DtAsType 通过类型枚举值获取类型结构体

func NameAsType

func NameAsType(typeName string) (*DataType, error)

NameAsType 通过类型名称获取类型结构体

type MetaDBSource

type MetaDBSource struct {
	OpenTime time.Time
	SyncTime time.Time
	Mu       *sync.Mutex
	// contains filtered or unexported fields
}

MetaDBSource 元数据库连接结构体

func OpenMetaConn

func OpenMetaConn() *MetaDBSource

OpenMetaConn 打开元数据库连接,主程序应该保存这个连接

func (*MetaDBSource) Close

func (c *MetaDBSource) Close()

Close 关闭META数据库连接

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更新到元数据中

Jump to

Keyboard shortcuts

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