casts

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CastIDToTableName

func CastIDToTableName(castID id.Cast) doltdb.TableName

CastIDToTableName returns the ID in a format that's better for user consumption.

func Init

func Init(
	getRunnerFromCtx func(ctx *sql.Context) (sql.StatementRunner, error),
	getIsStrictFromFunc func(f sql.Expression) bool,
	provider sql.FunctionProvider,
) map[id.Cast]Cast

Init initializes this package.

Types

type Cast

type Cast struct {
	ID       id.Cast
	CastType CastType
	Function id.Function
	BuiltIn  pgtypes.TypeCastFunction
	UseInOut bool
	// contains filtered or unexported fields
}

Cast represents a cast between two types.

func DeserializeCast

func DeserializeCast(ctx context.Context, data []byte) (Cast, error)

DeserializeCast returns the Cast that was serialized in the byte slice. Returns an empty Cast (invalid ID) if data is nil or empty.

func (Cast) Eval

func (cast Cast) Eval(ctx *sql.Context, val any, sourceType *pgtypes.DoltgresType, targetType *pgtypes.DoltgresType) (any, error)

Eval evaluates the cast against the given value.

func (Cast) GetID

func (cast Cast) GetID() id.Id

GetID implements the interface objinterface.RootObject.

func (Cast) GetRootObjectID

func (cast Cast) GetRootObjectID() objinterface.RootObjectID

GetRootObjectID implements the interface objinterface.RootObject.

func (Cast) HashOf

func (cast Cast) HashOf(ctx context.Context) (hash.Hash, error)

HashOf implements the interface objinterface.RootObject.

func (Cast) Name

func (cast Cast) Name() doltdb.TableName

Name implements the interface rootobject.RootObject.

func (Cast) Serialize

func (cast Cast) Serialize(ctx context.Context) ([]byte, error)

Serialize returns the Cast as a byte slice. If the Cast is invalid, then this returns a nil slice.

type CastType

type CastType uint8

CastType is the type of the cast, indicating which contexts it may be called in.

const (
	CastType_Explicit   CastType = 0
	CastType_Assignment CastType = 1
	CastType_Implicit   CastType = 2
)

type Collection

type Collection struct {
	objinterface.RootObjectMap
}

Collection contains a collection of casts.

func LoadCasts

func LoadCasts(ctx context.Context, root objinterface.RootValue) (*Collection, error)

LoadCasts loads the casts collection from the given root.

func NewCollection

func NewCollection(rom objinterface.RootObjectMap) *Collection

NewCollection returns a new Collection.

func (*Collection) AddCast

func (pgc *Collection) AddCast(ctx context.Context, cast Cast) error

AddCast adds a new cast.

func (*Collection) DeserializeRootObject

func (pgc *Collection) DeserializeRootObject(ctx context.Context, data []byte) (objinterface.RootObject, error)

DeserializeRootObject implements the interface objinterface.Collection.

func (*Collection) DiffRootObjects

DiffRootObjects implements the interface objinterface.Collection.

func (*Collection) DropCast

func (pgc *Collection) DropCast(ctx context.Context, castIDs ...id.Cast) error

DropCast drops an existing cast.

func (*Collection) DropRootObject

func (pgc *Collection) DropRootObject(ctx context.Context, identifier id.Id) error

DropRootObject implements the interface objinterface.Collection.

func (*Collection) GetAssignmentCast

func (pgc *Collection) GetAssignmentCast(ctx *sql.Context, sourceType *pgtypes.DoltgresType, targetType *pgtypes.DoltgresType) (Cast, error)

GetAssignmentCast returns the assignment type cast function that will cast the source type to the target type. Returns a Cast with an invalid ID if such a cast is not valid.

func (*Collection) GetExplicitCast

func (pgc *Collection) GetExplicitCast(ctx *sql.Context, sourceType *pgtypes.DoltgresType, targetType *pgtypes.DoltgresType) (Cast, error)

GetExplicitCast returns the explicit type cast function that will cast the source type to the target type. Returns a Cast with an invalid ID if such a cast is not valid.

func (*Collection) GetFieldType

func (pgc *Collection) GetFieldType(ctx context.Context, fieldName string) *pgtypes.DoltgresType

GetFieldType implements the interface objinterface.Collection.

func (*Collection) GetID

func (pgc *Collection) GetID() objinterface.RootObjectID

GetID implements the interface objinterface.Collection.

func (*Collection) GetImplicitCast

func (pgc *Collection) GetImplicitCast(ctx *sql.Context, sourceType *pgtypes.DoltgresType, targetType *pgtypes.DoltgresType) (Cast, error)

GetImplicitCast returns the implicit type cast function that will cast the source type to the target type. Returns a Cast with an invalid ID if such a cast is not valid.

func (*Collection) GetRootObject

func (pgc *Collection) GetRootObject(ctx context.Context, identifier id.Id) (objinterface.RootObject, bool, error)

GetRootObject implements the interface objinterface.Collection.

func (*Collection) HandleMerge

HandleMerge implements the interface objinterface.Collection.

func (*Collection) HasCast

func (pgc *Collection) HasCast(ctx context.Context, castID id.Cast) bool

HasCast returns whether the given cast exists.

func (*Collection) HasRootObject

func (pgc *Collection) HasRootObject(ctx context.Context, identifier id.Id) (bool, error)

HasRootObject implements the interface objinterface.Collection.

func (*Collection) IDToTableName

func (pgc *Collection) IDToTableName(identifier id.Id) doltdb.TableName

IDToTableName implements the interface objinterface.Collection.

func (*Collection) IterAll

func (pgc *Collection) IterAll(ctx context.Context, callback func(rootObj objinterface.RootObject) (stop bool, err error)) error

IterAll implements the interface objinterface.Collection.

func (*Collection) IterIDs

func (pgc *Collection) IterIDs(ctx context.Context, callback func(identifier id.Id) (stop bool, err error)) error

IterIDs implements the interface objinterface.Collection.

func (*Collection) IterateCasts

func (pgc *Collection) IterateCasts(ctx context.Context, callback func(c Cast) (stop bool, err error)) error

IterateCasts iterates over all casts in the collection.

func (*Collection) LoadCollection

LoadCollection implements the interface objinterface.Collection.

func (*Collection) PutRootObject

func (pgc *Collection) PutRootObject(ctx context.Context, rootObj objinterface.RootObject) error

PutRootObject implements the interface objinterface.Collection.

func (*Collection) RenameRootObject

func (pgc *Collection) RenameRootObject(ctx context.Context, oldName id.Id, newName id.Id) error

RenameRootObject implements the interface objinterface.Collection.

func (*Collection) ResolveName

func (pgc *Collection) ResolveName(ctx context.Context, name doltdb.TableName) (doltdb.TableName, id.Id, error)

ResolveName implements the interface objinterface.Collection.

func (*Collection) ResolveNameFromObjects

func (*Collection) ResolveNameFromObjects(ctx context.Context, name doltdb.TableName, rootObjects []objinterface.RootObject) (doltdb.TableName, id.Id, error)

ResolveNameFromObjects implements the interface objinterface.Collection.

func (*Collection) Serializer

Serializer implements the interface objinterface.Collection.

func (*Collection) TableNameToID

func (pgc *Collection) TableNameToID(name doltdb.TableName) id.Id

TableNameToID implements the interface objinterface.Collection.

func (*Collection) UpdateField

func (pgc *Collection) UpdateField(ctx context.Context, rootObject objinterface.RootObject, fieldName string, newValue any) (objinterface.RootObject, error)

UpdateField implements the interface objinterface.Collection.

Jump to

Keyboard shortcuts

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