edb/field.go
2020-03-14 02:02:56 +08:00

85 lines
1.3 KiB
Go

package main
import (
"regexp"
"strings"
)
var fieldMap map[string]ValueType
func init() {
fieldMap["bool"] = VT_BOOL
fieldMap["int"] = VT_INT
fieldMap["int16"] = VT_INT16
fieldMap["int32"] = VT_INT32
fieldMap["int64"] = VT_INT64
fieldMap["uint"] = VT_UINT
fieldMap["uint16"] = VT_UINT16
fieldMap["uint32"] = VT_UINT32
fieldMap["uint64"] = VT_UINT64
fieldMap["char"] = VT_CHAR
fieldMap["varchar"] = VT_VARCHAR
fieldMap["text"] = VT_TEXT
fieldMap["timestamp"] = VT_TIMESTAMP
fieldMap["date"] = VT_DATE
}
// ValueType 值 类型
type ValueType int
const (
// VT_BOOL 布尔类型
VT_BOOL ValueType = 00000 + iota
)
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
)
// Field 字段
type Field struct {
Key []byte
VT ValueType
ID uint16
ArrayNumber int
IsIndex bool
IsUnique bool
}
// Parse 从字符串中解析 var a int; a = 0; a < 0 && a > 5 ;
func (field *Field) Parse(code string) {
codes := strings.Split(code, ";")
re := regexp.MustCompile("var +([a-zA-Z_]+) +[a-zA-Z]+[8|16|32|64]{0,1}")
re.FindStringSubmatch(codes[0])
}