types

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package types provides data type definitions for XxSql storage engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDecimal

func FormatDecimal(unscaled int64, scale int) string

FormatDecimal formats an unscaled value with scale as a decimal string.

Types

type CheckConstraintInfo

type CheckConstraintInfo struct {
	Name       string `json:"name"`
	Expression string `json:"expression"` // SQL expression as string
}

CheckConstraintInfo represents a CHECK constraint.

type ColumnInfo

type ColumnInfo struct {
	Name       string
	Type       TypeID
	Size       int // For CHAR/VARCHAR
	Precision  int // For DECIMAL (not implemented yet)
	Scale      int // For DECIMAL (not implemented yet)
	Nullable   bool
	Default    Value
	PrimaryKey bool
	AutoIncr   bool
	Unique     bool
	Comment    string
}

ColumnInfo represents column metadata.

type ForeignKeyInfo

type ForeignKeyInfo struct {
	Name       string   `json:"name"`
	Columns    []string `json:"columns"`
	RefTable   string   `json:"ref_table"`
	RefColumns []string `json:"ref_columns"`
	OnDelete   string   `json:"on_delete"`
	OnUpdate   string   `json:"on_update"`
}

ForeignKeyInfo represents a FOREIGN KEY constraint.

type TypeID

type TypeID uint8

TypeID represents a data type identifier.

const (
	TypeNull TypeID = iota
	TypeSeq
	TypeInt
	TypeFloat
	TypeDecimal
	TypeChar
	TypeVarchar
	TypeText
	TypeDate
	TypeTime
	TypeDatetime
	TypeBool
	TypeBytes // For internal use
)

func ParseTypeID

func ParseTypeID(name string) TypeID

ParseTypeID parses a type name to TypeID.

func (TypeID) String

func (t TypeID) String() string

String returns the string representation of the type.

type Value

type Value struct {
	Type TypeID
	Data []byte
	Null bool
}

Value represents a typed value.

func NewBoolValue

func NewBoolValue(v bool) Value

NewBoolValue creates a boolean value.

func NewBytesValue

func NewBytesValue(v []byte) Value

NewBytesValue creates a bytes value.

func NewDateValue

func NewDateValue(v time.Time) Value

NewDateValue creates a date value.

func NewDatetimeValue

func NewDatetimeValue(v time.Time) Value

NewDatetimeValue creates a datetime value.

func NewDecimalFromString

func NewDecimalFromString(s string) (Value, error)

NewDecimalFromString creates a DECIMAL value from a string representation.

func NewDecimalValue

func NewDecimalValue(unscaled int64, scale int) Value

NewDecimalValue creates a DECIMAL value from an unscaled integer and scale. For example, NewDecimalValue(12345, 2) represents 123.45

func NewFloatValue

func NewFloatValue(v float64) Value

NewFloatValue creates a float value.

func NewIntValue

func NewIntValue(v int64) Value

NewIntValue creates an integer value.

func NewNullValue

func NewNullValue() Value

NewNullValue creates a null value.

func NewStringValue

func NewStringValue(v string, typ TypeID) Value

NewStringValue creates a string value (VARCHAR/CHAR/TEXT).

func NewTimeValue

func NewTimeValue(v time.Time) Value

NewTimeValue creates a time value.

func UnmarshalValue

func UnmarshalValue(data []byte, typ TypeID) (Value, int)

UnmarshalValue deserializes bytes to a value.

func (Value) AsBool

func (v Value) AsBool() bool

AsBool returns the value as bool.

func (Value) AsDatetime

func (v Value) AsDatetime() time.Time

AsDatetime returns the value as time.Time.

func (Value) AsDecimal

func (v Value) AsDecimal() (unscaled int64, scale int)

AsDecimal returns the unscaled value and scale for DECIMAL type. Returns (unscaled, scale) where the actual value is unscaled / 10^scale.

func (Value) AsDecimalString

func (v Value) AsDecimalString() string

AsDecimalString returns the DECIMAL value as a string.

func (Value) AsFloat

func (v Value) AsFloat() float64

AsFloat returns the value as float64.

func (Value) AsInt

func (v Value) AsInt() int64

AsInt returns the value as int64.

func (Value) AsString

func (v Value) AsString() string

AsString returns the value as string.

func (Value) Compare

func (v Value) Compare(other Value) int

Compare compares two values. Returns -1 if v < other, 0 if v == other, 1 if v > other.

func (Value) Marshal

func (v Value) Marshal() []byte

Marshal serializes the value to bytes.

func (Value) Size

func (v Value) Size() int

Size returns the storage size of the value.

func (Value) String

func (v Value) String() string

String returns a string representation of the value.

Jump to

Keyboard shortcuts

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