types

package
v0.0.0-...-7f9930a Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2015 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnspecifiedLength int = -1
)

UnspecifiedLength is unspecified length.

Variables

View Source
var Collators = map[bool]func(a, b []interface{}) int{/* contains filtered or unexported fields */}

Collators maps a boolean value to a collated function.

Functions

func Clone

func Clone(from interface{}) (interface{}, error)

Clone copies a interface to another interface. It does a deep copy.

func Coerce

func Coerce(a, b interface{}) (x, y interface{})

Coerce changes type. If a or b is Decimal, changes the both to Decimal. If a or b is Float, changes the both to Float.

func Compare

func Compare(a, b interface{}) int

Compare returns an integer comparing the interface a to b. TODO: compare should return errors instead of panicing.

func CompareFloat64

func CompareFloat64(x, y float64) int

CompareFloat64 returns an integer comparing the float64 x to y.

func CompareInt64

func CompareInt64(x, y int64) int

CompareInt64 returns an integer comparing the int64 x to y.

func CompareInteger

func CompareInteger(x int64, y uint64) int

CompareInteger returns an integer comparing the int64 x to the uint64 y.

func CompareString

func CompareString(x, y string) int

CompareString returns an integer comparing the string x to y.

func CompareUint64

func CompareUint64(x, y uint64) int

CompareUint64 returns an integer comparing the uint64 x to y.

func Convert

func Convert(val interface{}, target *FieldType) (v interface{}, err error)

Convert converts the val with type tp.

func EOFAsNil

func EOFAsNil(err error) error

EOFAsNil filtrates errors, If err is equal to io.EOF returns nil.

func FieldTypeToStr

func FieldTypeToStr(tp byte, cs string) (r string)

FieldTypeToStr converts a field to a string. It is used for converting Text to Blob, or converting Char to Binary. Args:

tp: type enum
cs: charset

func InvConv

func InvConv(val interface{}, tp byte) (interface{}, error)

InvConv returns a failed convertion error.

func InvOp2

func InvOp2(x, y interface{}, o opcode.Op) (interface{}, error)

InvOp2 returns an invalid operation error.

func IsOrderedType

func IsOrderedType(v interface{}) (y interface{}, r bool, err error)

IsOrderedType returns a boolean whether the type of y can be used by order by.

func IsTypeBlob

func IsTypeBlob(tp byte) bool

IsTypeBlob returns a boolean indicating whether the tp is a blob type.

func IsTypeChar

func IsTypeChar(tp byte) bool

IsTypeChar returns a boolean indicating whether the tp is the char type like a string type or a varchar type.

func Overflow

func Overflow(v interface{}, tp byte) error

Overflow returns an overflowed error.

func RoundFloat

func RoundFloat(val float64) float64

RoundFloat rounds float val to the nearest integer value with float64 format, like GNU rint function. RoundFloat uses default rounding mode, see http://www.gnu.org/software/libc/manual/html_node/Rounding.html so we will choose the even number if the result is midway between two representable value. e.g, 1.5 -> 2, 2.5 -> 2.

func StrToFloat

func StrToFloat(str string) (float64, error)

StrToFloat converts a string to a float64 in best effort.

func StrToInt

func StrToInt(str string) (int64, error)

StrToInt converts a string to an integer in best effort. TODO: handle overflow and add unittest.

func StrToUint

func StrToUint(str string) (uint64, error)

StrToUint converts a string to an unsigned integer in best effort. TODO: handle overflow and add unittest.

func ToBool

func ToBool(value interface{}) (int8, error)

ToBool converts a interface to a bool. We will use 1 for true, and 0 for false.

func ToDecimal

func ToDecimal(value interface{}) (mysql.Decimal, error)

ToDecimal converts a interface to the Decimal.

func ToFloat64

func ToFloat64(value interface{}) (float64, error)

ToFloat64 converts a interface to a float64.

func ToInt64

func ToInt64(value interface{}) (int64, error)

ToInt64 converts a interface to an int64.

func ToString

func ToString(value interface{}) (string, error)

ToString converts a interface to a string.

func TruncateFloat

func TruncateFloat(f float64, flen int, decimal int) (float64, error)

TruncateFloat tries to truncate f. If the result exceeds the max/min float that flen/decimal allowed, returns the max/min float allowed.

func TypeStr

func TypeStr(tp byte) (r string)

TypeStr converts tp to a string.

func TypeToStr

func TypeToStr(tp byte, binary bool) string

TypeToStr converts tp to a string with an extra binary.

func UndOp

func UndOp(x interface{}, o opcode.Op) (interface{}, error)

UndOp returns an undefined error.

Types

type FieldType

type FieldType struct {
	Tp      byte
	Flag    uint
	Flen    int
	Decimal int
	Charset string
	Collate string
}

FieldType records field type information.

func NewFieldType

func NewFieldType(tp byte) *FieldType

NewFieldType returns a FieldType, with a type and other information about field type.

func (*FieldType) String

func (ft *FieldType) String() string

String joins the information of FieldType and returns a string.

Jump to

Keyboard shortcuts

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