add sql type bool methods
This commit is contained in:
parent
e649ef538f
commit
724a99021f
99
type.go
99
type.go
|
@ -22,15 +22,35 @@ type SQLType struct {
|
||||||
DefaultLength2 int
|
DefaultLength2 int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
UNKNOW_TYPE = iota
|
||||||
|
TEXT_TYPE
|
||||||
|
BLOB_TYPE
|
||||||
|
TIME_TYPE
|
||||||
|
NUMERIC_TYPE
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *SQLType) IsType(st int) bool {
|
||||||
|
if t, ok := SqlTypes[s.Name]; ok && t == st {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SQLType) IsText() bool {
|
func (s *SQLType) IsText() bool {
|
||||||
return s.Name == Char || s.Name == Varchar || s.Name == TinyText ||
|
return s.IsType(TEXT_TYPE)
|
||||||
s.Name == Text || s.Name == MediumText || s.Name == LongText
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SQLType) IsBlob() bool {
|
func (s *SQLType) IsBlob() bool {
|
||||||
return (s.Name == TinyBlob) || (s.Name == Blob) ||
|
return s.IsType(BLOB_TYPE)
|
||||||
s.Name == MediumBlob || s.Name == LongBlob ||
|
}
|
||||||
s.Name == Binary || s.Name == VarBinary || s.Name == Bytea
|
|
||||||
|
func (s *SQLType) IsTime() bool {
|
||||||
|
return s.IsType(TIME_TYPE)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SQLType) IsNumeric() bool {
|
||||||
|
return s.IsType(NUMERIC_TYPE)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -75,46 +95,47 @@ var (
|
||||||
Serial = "SERIAL"
|
Serial = "SERIAL"
|
||||||
BigSerial = "BIGSERIAL"
|
BigSerial = "BIGSERIAL"
|
||||||
|
|
||||||
SqlTypes = map[string]bool{
|
SqlTypes = map[string]int{
|
||||||
Bit: true,
|
Bit: NUMERIC_TYPE,
|
||||||
TinyInt: true,
|
TinyInt: NUMERIC_TYPE,
|
||||||
SmallInt: true,
|
SmallInt: NUMERIC_TYPE,
|
||||||
MediumInt: true,
|
MediumInt: NUMERIC_TYPE,
|
||||||
Int: true,
|
Int: NUMERIC_TYPE,
|
||||||
Integer: true,
|
Integer: NUMERIC_TYPE,
|
||||||
BigInt: true,
|
BigInt: NUMERIC_TYPE,
|
||||||
|
|
||||||
Char: true,
|
Char: TEXT_TYPE,
|
||||||
Varchar: true,
|
Varchar: TEXT_TYPE,
|
||||||
TinyText: true,
|
TinyText: TEXT_TYPE,
|
||||||
Text: true,
|
Text: TEXT_TYPE,
|
||||||
MediumText: true,
|
MediumText: TEXT_TYPE,
|
||||||
LongText: true,
|
LongText: TEXT_TYPE,
|
||||||
|
|
||||||
Date: true,
|
Date: TIME_TYPE,
|
||||||
DateTime: true,
|
DateTime: TIME_TYPE,
|
||||||
Time: true,
|
Time: TIME_TYPE,
|
||||||
TimeStamp: true,
|
TimeStamp: TIME_TYPE,
|
||||||
TimeStampz: true,
|
TimeStampz: TIME_TYPE,
|
||||||
|
|
||||||
Decimal: true,
|
Decimal: NUMERIC_TYPE,
|
||||||
Numeric: true,
|
Numeric: NUMERIC_TYPE,
|
||||||
|
Real: NUMERIC_TYPE,
|
||||||
|
Float: NUMERIC_TYPE,
|
||||||
|
Double: NUMERIC_TYPE,
|
||||||
|
|
||||||
Binary: true,
|
Binary: BLOB_TYPE,
|
||||||
VarBinary: true,
|
VarBinary: BLOB_TYPE,
|
||||||
Real: true,
|
|
||||||
Float: true,
|
|
||||||
Double: true,
|
|
||||||
TinyBlob: true,
|
|
||||||
Blob: true,
|
|
||||||
MediumBlob: true,
|
|
||||||
LongBlob: true,
|
|
||||||
Bytea: true,
|
|
||||||
|
|
||||||
Bool: true,
|
TinyBlob: BLOB_TYPE,
|
||||||
|
Blob: BLOB_TYPE,
|
||||||
|
MediumBlob: BLOB_TYPE,
|
||||||
|
LongBlob: BLOB_TYPE,
|
||||||
|
Bytea: BLOB_TYPE,
|
||||||
|
|
||||||
Serial: true,
|
Bool: NUMERIC_TYPE,
|
||||||
BigSerial: true,
|
|
||||||
|
Serial: NUMERIC_TYPE,
|
||||||
|
BigSerial: NUMERIC_TYPE,
|
||||||
}
|
}
|
||||||
|
|
||||||
intTypes = sort.StringSlice{"*int", "*int16", "*int32", "*int8"}
|
intTypes = sort.StringSlice{"*int", "*int16", "*int32", "*int8"}
|
||||||
|
|
Loading…
Reference in New Issue