From a0677f2451f7dd76602e40e329e460a57a0e7973 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 12 Mar 2020 16:59:56 +0800 Subject: [PATCH] =?UTF-8?q?Parse=20=E5=AD=97=E6=AE=B5=20=E6=96=B0=E6=80=9D?= =?UTF-8?q?=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rocksdb.go | 77 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/rocksdb.go b/rocksdb.go index 8c5f925..62a3f73 100644 --- a/rocksdb.go +++ b/rocksdb.go @@ -4,6 +4,8 @@ import ( "fmt" "log" "os" + "sync" + "sync/atomic" "time" "github.com/tecbot/gorocksdb" @@ -51,20 +53,58 @@ type Metadata struct { tidCount uint32 // int16 } -type Field struct { - Key string +type ValueType int - ValueType int - ID int +const ( + VT_INT ValueType = 10000 + iota + VT_INT8 + VT_INT16 + VT_INT32 + VT_INT64 +) + +const ( + VT_UINT ValueType = 11000 + iota + VT_UINT8 + VT_UINT16 + VT_UINT32 + VT_UINT64 +) + +const ( + VT_CHAR ValueType = 12000 + iota + VT_VARCHAR + VT_TEXT +) + +const ( + VT_TIMESTAMP ValueType = 13000 + iota + VT_DATE +) + +type Field struct { + Key []byte + + VT ValueType + ID uint16 IsIndex bool IsUnique bool } +// Parse 从字符串中解析 var a int; a = 0; a < 0 && a > 5 ; +func (field *Field) Parse(code string) { + +} + +// Table 表结构 type Table struct { + tableLock *sync.Mutex + Name string Type int - ID uint32 // uint16 + + ID uint32 // uint16 IsAllKey bool Fields []*Field @@ -75,17 +115,36 @@ type Table struct { delCount uint64 } -func CreateTable(name string, field []*Field) { +// CreateField 创建字段 +func (table *Table) CreateField(key []byte, vt ValueType, isIndex bool, isUnique bool) *Field { + + table.tableLock.Lock() + defer table.tableLock.Unlock() + + field := &Field{} + field.ID = table.fidCount + field.IsIndex = isIndex + field.IsUnique = isUnique + field.Key = key + field.VT = vt + + table.fidCount++ + + return field +} + +// CreateTable 创建表 +func CreateTable(name string, fields []*Field) { if _, ok := EDB.TableDict[name]; !ok { - // ntid := atomic.AddUint32(&EDB.Metadata.tidCount, 1) - // table := &Table{Name: name, ID: ntid, Type: 1} + ntid := atomic.AddUint32(&EDB.Metadata.tidCount, 1) + table := &Table{Name: name, ID: ntid, Type: 1} + table.Fields = fields } else { log.Println("table name is exists") } } -// gson // OpenDataBase (cf-key.{tableid(2)}{fieldid(2)}) {value}{indexid(6)} = {rowid(6)} (cf-row.{tableid(2)} {row-sharding-id}){rowid(6)} = {values} func OpenDataBase() (*gorocksdb.DB, []*gorocksdb.ColumnFamilyHandle) {