typeinfo

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DateType      = &datetimeType{sql.Date}
	DatetimeType  = &datetimeType{sql.Datetime}
	TimestampType = &datetimeType{sql.Timestamp}
)
View Source
var (
	Float32Type = &floatType{sql.Float32}
	Float64Type = &floatType{sql.Float64}
)
View Source
var (
	Int8Type  = &intType{sql.Int8}
	Int16Type = &intType{sql.Int16}
	Int24Type = &intType{sql.Int24}
	Int32Type = &intType{sql.Int32}
	Int64Type = &intType{sql.Int64}
)
View Source
var (
	Uint8Type  = &uintType{sql.Uint8}
	Uint16Type = &uintType{sql.Uint16}
	Uint24Type = &uintType{sql.Uint24}
	Uint32Type = &uintType{sql.Uint32}
	Uint64Type = &uintType{sql.Uint64}
)
View Source
var (
	LegacyStringDefaultType = &varStringType{sql.CreateLongText(sql.Collation_Default)}
	StringDefaultType       = &varStringType{sql.MustCreateStringWithDefaults(sqltypes.VarChar, 16383)}
)
View Source
var GeometryType = &geometryType{sql.GeometryType{}, nil}
View Source
var IncompatibleTypeConversion = errors.NewKind("`%s` cannot convert any values to `%s`")
View Source
var InvalidTypeConversion = errors.NewKind("`%s` cannot convert the value `%v` to `%s`")
View Source
var JSONType = &jsonType{sql.JSON}
View Source
var LinestringType = &linestringType{sql.LinestringType{}}
View Source
var PointType = &pointType{sql.PointType{}}
View Source
var PolygonType = &polygonType{sql.PolygonType{}}
View Source
var TimeType = &timeType{sql.Time}
View Source
var TupleType = &tupleType{}

This is for internal use only. Used in merge conflicts.

View Source
var UnhandledTypeConversion = errors.NewKind("`%s` does not know how to handle type conversions to `%s`")
View Source
var YearType = &yearType{sql.Year}

Functions

func ConvertSQLGeometryToTypesGeometry

func ConvertSQLGeometryToTypesGeometry(p sql.Geometry) types.Geometry

func ConvertSQLLinestringToTypesLinestring

func ConvertSQLLinestringToTypesLinestring(l sql.Linestring) types.Linestring

func ConvertSQLPointToTypesPoint

func ConvertSQLPointToTypesPoint(p sql.Point) types.Point

func ConvertSQLPolygonToTypesPolygon

func ConvertSQLPolygonToTypesPolygon(p sql.Polygon) types.Polygon

func ConvertTypesGeometryToSQLGeometry

func ConvertTypesGeometryToSQLGeometry(g types.Geometry) sql.Geometry

ConvertTypesGeometryToSQLGeometry basically makes a deep copy of sql.Geometry

func ConvertTypesLinestringToSQLLinestring

func ConvertTypesLinestringToSQLLinestring(l types.Linestring) sql.Linestring

ConvertTypesLinestringToSQLLinestring basically makes a deep copy of sql.Linestring

func ConvertTypesPointToSQLPoint

func ConvertTypesPointToSQLPoint(p types.Point) sql.Point

ConvertTypesPointToSQLPoint basically makes a deep copy of sql.Point

func ConvertTypesPolygonToSQLPolygon

func ConvertTypesPolygonToSQLPolygon(p types.Polygon) sql.Polygon

ConvertTypesPolygonToSQLPolygon basically makes a deep copy of sql.Linestring

func IsStringType

func IsStringType(ti TypeInfo) bool

IsStringType returns whether the given TypeInfo represents a CHAR, VARCHAR, or TEXT-derivative.

Types

type FloatWidth

type FloatWidth int8

type Identifier

type Identifier string
const (
	UnknownTypeIdentifier    Identifier = "unknown"
	BitTypeIdentifier        Identifier = "bit"
	BlobStringTypeIdentifier Identifier = "blobstring"
	BoolTypeIdentifier       Identifier = "bool"
	DatetimeTypeIdentifier   Identifier = "datetime"
	DecimalTypeIdentifier    Identifier = "decimal"
	EnumTypeIdentifier       Identifier = "enum"
	FloatTypeIdentifier      Identifier = "float"
	JSONTypeIdentifier       Identifier = "json"
	InlineBlobTypeIdentifier Identifier = "inlineblob"
	IntTypeIdentifier        Identifier = "int"
	SetTypeIdentifier        Identifier = "set"
	TimeTypeIdentifier       Identifier = "time"
	TupleTypeIdentifier      Identifier = "tuple"
	UintTypeIdentifier       Identifier = "uint"
	UuidTypeIdentifier       Identifier = "uuid"
	VarBinaryTypeIdentifier  Identifier = "varbinary"
	VarStringTypeIdentifier  Identifier = "varstring"
	YearTypeIdentifier       Identifier = "year"
	GeometryTypeIdentifier   Identifier = "geometry"
	PointTypeIdentifier      Identifier = "point"
	LinestringTypeIdentifier Identifier = "linestring"
	PolygonTypeIdentifier    Identifier = "polygon"
)

func ParseIdentifier

func ParseIdentifier(name string) Identifier

ParseIdentifier takes in an Identifier in string form and returns the matching Identifier. Returns UnknownTypeIdentifier when the string match is not found.

func (Identifier) String

func (i Identifier) String() string

String returns a string representation of the identifier. This may later be used in parsing to retrieve the original identifier.

type TypeConverter

type TypeConverter func(ctx context.Context, vrw types.ValueReadWriter, v types.Value) (types.Value, error)

TypeConverter is a function that is used to convert a Noms value from one TypeInfo to another.

func GetTypeConverter

func GetTypeConverter(ctx context.Context, srcTi TypeInfo, destTi TypeInfo) (tc TypeConverter, needsConversion bool, err error)

GetTypeConverter returns a TypeConverter that will convert a Noms value from the source type to the destination type. If the source type does not have a valid converter for the destination type, then this returns an error. When the given types are similar enough, no conversion is needed, thus this will return false. In such cases, although a valid TypeConverter will still be returned, it is equivalent to calling IsValid on the destination TypeInfo. Rather than returning nil values, any such returned nils will instead be types.NullValue.

type TypeInfo

type TypeInfo interface {
	// ConvertNomsValueToValue converts a Noms value to a go value. The expected NomsKind of the given
	// parameter is equivalent to the NomsKind returned by this type info. This is intended for retrieval
	// from storage, thus we do no validation as we assume the stored value is already validated against
	// the given type.
	ConvertNomsValueToValue(v types.Value) (interface{}, error)

	// ReadFrom reads a go value from a noms types.CodecReader directly
	ReadFrom(nbf *types.NomsBinFormat, reader types.CodecReader) (interface{}, error)

	// ConvertValueToNomsValue converts a go value or Noms value to a Noms value. The type of the Noms
	// value will be equivalent to the NomsKind returned from NomsKind.
	ConvertValueToNomsValue(ctx context.Context, vrw types.ValueReadWriter, v interface{}) (types.Value, error)

	// Equals returns whether the given TypeInfo is equivalent to this TypeInfo.
	Equals(other TypeInfo) bool

	// FormatValue returns the stringified version of the value.
	FormatValue(v types.Value) (*string, error)

	// GetTypeIdentifier returns an identifier for this type used for serialization.
	GetTypeIdentifier() Identifier

	// GetTypeParams returns a map[string]string containing the type parameters.  This is used for
	// serialization and deserialization of type information.
	GetTypeParams() map[string]string

	// IsValid takes in a types.Value and returns whether it is valid for this type.
	IsValid(v types.Value) bool

	// NomsKind returns the NomsKind that best matches this TypeInfo.
	NomsKind() types.NomsKind

	// Promote will promote the current TypeInfo to the largest representing TypeInfo of the same kind, such as Int8 to Int64.
	Promote() TypeInfo

	// ToSqlType returns the TypeInfo as a sql.Type. If an exact match is able to be made then that is
	// the one returned, otherwise the sql.Type is the closest match possible.
	ToSqlType() sql.Type

	// Stringer results are used to inform users of the constraint's properties.
	fmt.Stringer
}

TypeInfo is an interface used for encoding type information.

var BoolType TypeInfo = &boolType{sql.MustCreateBitType(1)}
var PseudoBoolType TypeInfo = &bitType{sql.MustCreateBitType(1)}
var UnknownType TypeInfo = &unknownType{}

func CreateBitTypeFromParams

func CreateBitTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateBlobStringTypeFromParams

func CreateBlobStringTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateDatetimeTypeFromParams

func CreateDatetimeTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateDecimalTypeFromParams

func CreateDecimalTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateEnumTypeFromParams

func CreateEnumTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateFloatTypeFromParams

func CreateFloatTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateInlineBlobTypeFromParams

func CreateInlineBlobTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateIntTypeFromParams

func CreateIntTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateSetTypeFromParams

func CreateSetTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateUintTypeFromParams

func CreateUintTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateVarBinaryTypeFromParams

func CreateVarBinaryTypeFromParams(params map[string]string) (TypeInfo, error)

func CreateVarStringTypeFromParams

func CreateVarStringTypeFromParams(params map[string]string) (TypeInfo, error)

func FromKind

func FromKind(kind types.NomsKind) TypeInfo

FromKind returns the default TypeInfo for a given types.Value.

func FromSqlType

func FromSqlType(sqlType sql.Type) (TypeInfo, error)

FromSqlType takes in a sql.Type and returns the most relevant TypeInfo.

func FromTypeParams

func FromTypeParams(id Identifier, params map[string]string) (TypeInfo, error)

FromTypeParams constructs a TypeInfo from the given identifier and parameters.

Jump to

Keyboard shortcuts

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