gcvctor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 16 Imported by: 1

Documentation

Overview

Package gcvctor constructs cloud.google.com/go/spanner.GenericColumnValue values from Go values and explicit cloud.google.com/go/spanner/apiv1/spannerpb.Type metadata, using github.com/apstndb/spantype/typector for type shapes.

ArrayValue infers the element type from the first element (or uses a default empty ARRAY<INT64> when len==0, whether the variadic slice is nil or empty). ArrayValueOf takes the element type explicitly; len==0 yields an empty ARRAY<elemType>. For a SQL NULL ARRAY, use NullOf with github.com/apstndb/spantype/typector.ElemTypeToArrayType or github.com/apstndb/spantype/typector.ElemCodeToArrayType instead of relying on variadic nil. StructValueOf pairs field names with values; counts must match.

ARRAY-typed cloud.google.com/go/spanner/apiv1/spannerpb.Type values require array_element_type (protobuf: array_element_type; Go field name ArrayElementType); omitting it yields an invalid ARRAY shape and Spanner may reject the request.

Zero-argument ArrayValue returns an empty ARRAY<INT64> with complete type metadata in the Type field of the cloud.google.com/go/spanner.GenericColumnValue. For empty arrays, callers typically must supply explicit SQL type information through these constructors or through the ParamTypes field (protobuf: param_types) on cloud.google.com/go/spanner/apiv1/spannerpb.ExecuteSqlRequest, because an empty list value does not specify an element type by itself.

NullOf returns a typed NULL for any cloud.google.com/go/spanner/apiv1/spannerpb.Type, including STRUCT and ARRAY; the cloud.google.com/go/spanner.GenericColumnValue Value field is always a scalar protobuf null at the top level. NullFromCode does the same for simple scalar type codes only—it cannot express STRUCT field layouts or ARRAY element types. Neither encodes a non-null STRUCT whose fields are all null; use StructValueOf with per-field nulls when you need that shape.

Formatting these values as strings is provided by the sibling package github.com/apstndb/spanvalue.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTypeMismatch is returned by [ArrayValueOf] when an element's type does not match elemType.
	ErrTypeMismatch = errors.New("gcvctor: type mismatch")
	// ErrMismatchedCounts is returned by [StructValueOf] when len(names) != len(gcvs).
	ErrMismatchedCounts = errors.New("gcvctor: mismatched name/value count")
	// ErrNilElementType is returned by [ArrayValueOf] when elemType is nil.
	ErrNilElementType = errors.New("gcvctor: nil array element type")
)

Functions

func ArrayCodeTypedNull deprecated added in v0.1.10

func ArrayCodeTypedNull(elemCode sppb.TypeCode) spanner.GenericColumnValue

ArrayCodeTypedNull is an alias for NullArrayFromCode.

Deprecated: use NullArrayFromCode.

func ArrayTypeTypedNull deprecated added in v0.1.10

func ArrayTypeTypedNull(elemType *sppb.Type) spanner.GenericColumnValue

ArrayTypeTypedNull is an alias for NullArrayOf.

Deprecated: use NullArrayOf.

func ArrayValue

ArrayValue constructs ARRAY GenericColumnValue.

With no elements (including a nil or empty variadic slice), it returns an empty ARRAY<INT64> (SQL length zero, not SQL NULL), using a concrete element type so the Type field is a well-formed cloud.google.com/go/spanner/apiv1/spannerpb.Type (including array_element_type for ARRAY shapes). For a typed NULL ARRAY<INT64>, use NullOf with github.com/apstndb/spantype/typector.ElemCodeToArrayType (or github.com/apstndb/spantype/typector.ElemTypeToArrayType).

For other element types or explicit typing policy, use ArrayValueOf or EmptyArrayOf.

Note: Currently, it doesn't support implicit type conversion a.k.a. coercion so variant typed input is not supported.

func ArrayValueOf added in v0.2.0

func ArrayValueOf(elemType *sppb.Type, elems ...spanner.GenericColumnValue) (spanner.GenericColumnValue, error)

ArrayValueOf constructs ARRAY GenericColumnValue using elemType as the element type instead of inferring it from the first element. When elems is empty (nil or length zero), it returns an empty ARRAY<elemType> (SQL length zero, not SQL NULL). For a typed NULL ARRAY<elemType>, use NullOf with github.com/apstndb/spantype/typector.ElemTypeToArrayType or github.com/apstndb/spantype/typector.ElemCodeToArrayType.

Each element's Type must match elemType (no coercion). A nil elemType returns ErrNilElementType.

func ArrayValueWithType deprecated added in v0.2.0

func ArrayValueWithType(elemType *sppb.Type, elems ...spanner.GenericColumnValue) (spanner.GenericColumnValue, error)

ArrayValueWithType is an alias for ArrayValueOf.

Deprecated: use ArrayValueOf.

func BoolValue

func BoolValue(v bool) spanner.GenericColumnValue

BoolValue returns a non-null BOOL GenericColumnValue.

func BytesBasedValue deprecated

func BytesBasedValue(typ *sppb.Type, v []byte) spanner.GenericColumnValue

BytesBasedValue is an alias for BytesBasedValueOf.

Deprecated: use BytesBasedValueOf.

func BytesBasedValueOf added in v0.2.0

func BytesBasedValueOf(typ *sppb.Type, v []byte) spanner.GenericColumnValue

BytesBasedValueOf constructs a GenericColumnValue with an arbitrary bytes-compatible cloud.google.com/go/spanner/apiv1/spannerpb.Type and base64-encoded payload in Value.

func BytesValue

func BytesValue(v []byte) spanner.GenericColumnValue

BytesValue returns a non-null BYTES GenericColumnValue (base64 wire encoding).

func DateValue

func DateValue(v civil.Date) spanner.GenericColumnValue

DateValue returns a non-null DATE GenericColumnValue.

func ElemTypeCodeToEmptyArray deprecated added in v0.1.7

func ElemTypeCodeToEmptyArray(code sppb.TypeCode) spanner.GenericColumnValue

ElemTypeCodeToEmptyArray is an alias for EmptyArrayFromCode.

Deprecated: use EmptyArrayFromCode.

func ElemTypeToEmptyArray deprecated added in v0.1.7

func ElemTypeToEmptyArray(typ *sppb.Type) spanner.GenericColumnValue

ElemTypeToEmptyArray is an alias for EmptyArrayOf.

Deprecated: use EmptyArrayOf.

func EmptyArrayFromCode added in v0.2.0

func EmptyArrayFromCode(code sppb.TypeCode) spanner.GenericColumnValue

EmptyArrayFromCode returns a non-null empty ARRAY<T> for a simple scalar element type code.

func EmptyArrayOf added in v0.2.0

func EmptyArrayOf(elemType *sppb.Type) spanner.GenericColumnValue

EmptyArrayOf returns a non-null empty ARRAY<elemType> (length zero).

func EnumValue

func EnumValue(fqn string, v int64) spanner.GenericColumnValue

EnumValue returns a non-null ENUM GenericColumnValue for the fully qualified enum name fqn.

func Float32Value added in v0.1.5

func Float32Value(v float32) spanner.GenericColumnValue

Float32Value returns a non-null FLOAT32 GenericColumnValue. NaN and ±Inf use string wire values matching Spanner's encoding.

func Float64Value

func Float64Value(v float64) spanner.GenericColumnValue

Float64Value returns a non-null FLOAT64 GenericColumnValue. NaN and ±Inf use string wire values matching Spanner's encoding.

func Int64Value

func Int64Value(v int64) spanner.GenericColumnValue

Int64Value returns a non-null INT64 GenericColumnValue (decimal string wire format).

func IntervalValue added in v0.1.6

func IntervalValue(v spanner.Interval) spanner.GenericColumnValue

IntervalValue returns a non-null INTERVAL GenericColumnValue.

func JSONValue

func JSONValue(v any) (spanner.GenericColumnValue, error)

JSONValue marshals v to JSON and returns a non-null JSON GenericColumnValue.

func NullArrayFromCode added in v0.2.0

func NullArrayFromCode(elemCode sppb.TypeCode) spanner.GenericColumnValue

NullArrayFromCode returns a typed SQL NULL for ARRAY<T> where T is a simple scalar type code.

func NullArrayOf added in v0.2.0

func NullArrayOf(elemType *sppb.Type) spanner.GenericColumnValue

NullArrayOf returns a typed SQL NULL for ARRAY<elemType>.

func NullFromCode added in v0.2.0

func NullFromCode(code sppb.TypeCode) spanner.GenericColumnValue

NullFromCode returns a typed SQL NULL for a simple scalar type code. The cloud.google.com/go/spanner.GenericColumnValue Value field is always a protobuf NullValue; see NullOf for STRUCT and ARRAY semantics.

func NullOf added in v0.2.0

func NullOf(typ *sppb.Type) spanner.GenericColumnValue

NullOf returns a typed SQL NULL for typ. The cloud.google.com/go/spanner.GenericColumnValue Value field is always a protobuf NullValue, including when typ is STRUCT or ARRAY. It does not represent a non-null STRUCT whose fields are all null—use StructValueOf with per-field nulls (using NullOf or NullFromCode for each field) when you need that shape.

func NumericValue

func NumericValue(v *big.Rat) spanner.GenericColumnValue

NumericValue returns a non-null NUMERIC GenericColumnValue.

func ProtoValue

func ProtoValue(fqn string, b []byte) spanner.GenericColumnValue

ProtoValue returns a non-null PROTO GenericColumnValue for the fully qualified message name fqn.

func SimpleTypedNull deprecated

func SimpleTypedNull(code sppb.TypeCode) spanner.GenericColumnValue

SimpleTypedNull is an alias for NullFromCode.

Deprecated: use NullFromCode.

func StringBasedValue deprecated

func StringBasedValue(code sppb.TypeCode, v string) spanner.GenericColumnValue

StringBasedValue is an alias for StringBasedValueFromCode.

Deprecated: use StringBasedValueFromCode.

func StringBasedValueFromCode added in v0.2.0

func StringBasedValueFromCode(code sppb.TypeCode, v string) spanner.GenericColumnValue

StringBasedValueFromCode constructs a GenericColumnValue for a simple scalar type code with a string wire payload.

func StringValue

func StringValue(v string) spanner.GenericColumnValue

StringValue returns a non-null STRING GenericColumnValue.

func StructValue deprecated

func StructValue(names []string, gcvs []spanner.GenericColumnValue) (spanner.GenericColumnValue, error)

StructValue is an alias for StructValueOf.

Deprecated: use StructValueOf.

func StructValueOf added in v0.2.0

func StructValueOf(names []string, gcvs []spanner.GenericColumnValue) (spanner.GenericColumnValue, error)

StructValueOf constructs STRUCT GenericColumnValue. Note: Currently, it doesn't support implicit type conversion a.k.a. coercion so variant typed input is not supported.

func TimestampValue

func TimestampValue(v time.Time) spanner.GenericColumnValue

TimestampValue returns a non-null TIMESTAMP GenericColumnValue (RFC3339Nano string wire format).

func TypedNull deprecated

func TypedNull(typ *sppb.Type) spanner.GenericColumnValue

TypedNull is an alias for NullOf.

Deprecated: use NullOf.

func UUIDValue added in v0.1.8

func UUIDValue(v uuid.UUID) spanner.GenericColumnValue

UUIDValue returns a non-null UUID GenericColumnValue.

Types

This section is empty.

Jump to

Keyboard shortcuts

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