Skip to content

v0.1.0

Choose a tag to compare

@apstndb apstndb released this 10 Jun 14:42
16e3ad7

Initial release. Experimental: the API may change while encodeValue parity is proven against client library releases. Mirrored behavior tracks cloud.google.com/go/spanner v1.84.1.

Added

  • ValueOf(any) (spanner.GenericColumnValue, error) — Go value → GCV mirroring the client's internal encodeValue: all concrete parameter/mutation types (scalars, spanner.Null* wrappers including sql.NullString and uuid.NullUUID, pointers and slices with typed-NULL rules), spanner.Encoder, protobuf messages and enums (including typed-nil → typed NULL), named variants of base types (getDecodableSpannerType behavior), Go structs and struct slices as STRUCT values, spanner.CommitTimestamp, and GenericColumnValue passthrough (deep clone).
  • TypeFor[T]() / TypeFromGoType(reflect.Type) — static Go type → *sppb.Type inference; ErrTypeNotInferable for value-dependent types (spanner.Encoder, GenericColumnValue, NullProtoMessage/NullProtoEnum, interfaces).
  • StructColumns[T]() / StructColumnsFromGoTypespanner-tag column names with the client's mutation/ToStruct field listing (embedded flattening, shadowing, spanner:"-"), the helper requested in googleapis/google-cloud-go#13800.
  • RowTypeFor[T]() / RowTypeFromGoType — row-shaped *sppb.StructType for writer metadata.
  • StructColumnsAndValues(any) — struct → column names + GCVs for spanvalue/writer.
  • MutationColumnsAndValues(any) / MutationMap(any) — struct → plain Go cols/vals or map for the non-Struct mutation constructors (spanner.Update, spanner.UpdateMap, ...), enabling column masking by name.
  • ValuesFromSlice[T] / ArrayValueFromSlice[T] — homogeneous slice → (element *sppb.Type, []*structpb.Value) or ARRAY GCV; interface element types rejected.
  • Sentinel errors: ErrUnsupportedType, ErrUntypedNil, ErrNotStruct, ErrNilStructPointer, ErrEmbeddedStructField, ErrTypeNotInferable, ErrInvalidSource, ErrNumericOutOfRange.

Semantics

Deliberate strictness divergences from the client are documented in the package documentation: untyped nil and nil struct pointers return errors, GCV inputs with nil Type are rejected, NUMERIC is always validated, and non-finite floats / JSON use gcvctor's canonical wire forms.

Dependencies

  • github.com/apstndb/structfields v0.1.0 — Apache-2.0 exported fork of cloud.google.com/go/internal/fields; all upstream-derived code lives there, keeping spanenc MIT.
  • github.com/apstndb/spanvalue is pinned to a pseudo-version of main (v0.7.1-0.20260610130420) because v0.7.0 predates gcvctor's UTC-timestamp fix; it will move to the next tagged release.