Documentation
¶
Index ¶
- Variables
- func FormatBracketStruct(typ *sppb.Type, toplevel bool, fieldStrings []string) string
- func FormatColumnLiteral(value spanner.GenericColumnValue) (string, error)
- func FormatColumnSpannerCLICompatible(value spanner.GenericColumnValue) (string, error)
- func FormatCompactArray(_ *sppb.Type, _ bool, elemStrings []string) string
- func FormatEnumAsCast(formatter Formatter, value spanner.GenericColumnValue, toplevel bool) (string, error)
- func FormatJSONSimpleValue(_ Formatter, value spanner.GenericColumnValue, _ bool) (string, error)
- func FormatNullableSpannerCLICompatible(value NullableValue) (string, error)
- func FormatOptionallyTypedArray(typ *sppb.Type, toplevel bool, elemStrings []string) string
- func FormatProtoAsCast(formatter Formatter, value spanner.GenericColumnValue, toplevel bool) (string, error)
- func FormatRowJSONObject(fc *FormatConfig, row *spanner.Row, namer UnnamedFieldNamer) (string, error)
- func FormatRowLiteral(value *spanner.Row) ([]string, error)
- func FormatRowSpannerCLICompatible(row *spanner.Row) ([]string, error)
- func FormatSimpleStructField(fc *FormatConfig, field *sppb.StructType_Field, value *structpb.Value) (string, error)
- func FormatTupleStruct(typ *sppb.Type, toplevel bool, fieldStrings []string) string
- func FormatTypelessStructField(fc *FormatConfig, field *sppb.StructType_Field, value *structpb.Value) (string, error)
- func FormatUntypedArray(_ *sppb.Type, _ bool, elemStrings []string) string
- func IndexedUnnamedFieldNamer(index int) string
- type FormatArrayFunc
- type FormatComplexFunc
- type FormatConfig
- type FormatNullableFunc
- type FormatStruct
- type FormatStructFieldFunc
- type FormatStructParenFunc
- type Formatter
- type NullBytes
- type NullableValue
- type UnnamedFieldNamer
Constants ¶
This section is empty.
Variables ¶
var ErrFallthrough = errors.New("fallthrough")
var FormatJSONObjectStruct = NewJSONObjectStructFormatter(nil)
FormatJSONObjectStruct formats struct fields as a JSON object with nil namer. Unnamed struct fields produce empty-string keys, matching Spanner's own representation.
var FormatTypedStruct = FormatStruct{
FormatStructParen: formatTypedStructParen,
FormatStructField: formatSimpleStructField,
}
var LiteralFormatConfig = &FormatConfig{ NullString: nullStringUpperCase, FormatArray: FormatOptionallyTypedArray, FormatStruct: FormatTypedStruct, FormatNullable: formatNullableValueLiteral, FormatComplexPlugins: []FormatComplexFunc{ FormatProtoAsCast, FormatEnumAsCast, }, }
var SimpleFormatConfig = FormatConfig{ NullString: nullStringClientLib, FormatArray: FormatUntypedArray, FormatStruct: FormatStruct{ FormatStructField: FormatTypelessStructField, FormatStructParen: FormatTupleStruct, }, FormatNullable: formatNullableValueSimple, }
var SpannerCLICompatibleFormatConfig = FormatConfig{ NullString: nullStringUpperCase, FormatArray: FormatUntypedArray, FormatStruct: FormatStruct{ FormatStructField: FormatSimpleStructField, FormatStructParen: FormatBracketStruct, }, FormatNullable: FormatNullableSpannerCLICompatible, }
Functions ¶
func FormatBracketStruct ¶
func FormatColumnLiteral ¶
func FormatColumnLiteral(value spanner.GenericColumnValue) (string, error)
func FormatColumnSpannerCLICompatible ¶
func FormatColumnSpannerCLICompatible(value spanner.GenericColumnValue) (string, error)
func FormatCompactArray ¶ added in v0.1.9
FormatCompactArray formats array elements without spaces between separators. Output: [elem1,elem2,elem3]
func FormatEnumAsCast ¶
func FormatJSONSimpleValue ¶ added in v0.1.9
FormatJSONSimpleValue is a FormatComplexFunc that formats all non-ARRAY, non-STRUCT types as valid JSON values. It never returns ErrFallthrough.
For most types, structpb.Value.MarshalJSON() produces the correct JSON representation (BOOL→true/false, FLOAT→number, STRING→"quoted", NULL→null, NaN/Inf→"NaN"/"Infinity"). Only INT64, ENUM, and JSON columns need special handling:
- INT64: Spanner encodes as StringValue("42"), MarshalJSON() would produce "42" (quoted), but we want 42 (unquoted number).
- ENUM: Spanner stores proto enum values as INT64; same handling as INT64.
- JSON: Spanner encodes as StringValue('{"key":"value"}'), MarshalJSON() would produce escaped quoted string, but we want the raw JSON value passed through.
func FormatNullableSpannerCLICompatible ¶
func FormatNullableSpannerCLICompatible(value NullableValue) (string, error)
func FormatProtoAsCast ¶
func FormatRowJSONObject ¶ added in v0.1.9
func FormatRowJSONObject(fc *FormatConfig, row *spanner.Row, namer UnnamedFieldNamer) (string, error)
FormatRowJSONObject formats a spanner.Row as a single JSON object string using the given FormatConfig for value formatting and column names as keys. The FormatConfig must produce standalone JSON values per column (e.g., JSONFormatConfig()). Using a non-JSON config produces syntactically invalid output. Empty column names (e.g., from expressions without aliases like SELECT 1+1) are assigned names by the provided namer function. If namer is nil, empty names are kept as empty-string JSON keys. Output: {"col1":val1,"col2":val2,...}
func FormatSimpleStructField ¶
func FormatSimpleStructField(fc *FormatConfig, field *sppb.StructType_Field, value *structpb.Value) (string, error)
func FormatTupleStruct ¶
func FormatTypelessStructField ¶
func FormatTypelessStructField(fc *FormatConfig, field *sppb.StructType_Field, value *structpb.Value) (string, error)
func FormatUntypedArray ¶
func IndexedUnnamedFieldNamer ¶ added in v0.1.9
IndexedUnnamedFieldNamer produces names like "_0", "_1", etc. The underscore prefix minimizes collision with user-defined names. Suitable for row columns (e.g., SELECT 1+1 produces "_0").
Types ¶
type FormatArrayFunc ¶
type FormatComplexFunc ¶
type FormatComplexFunc = func(formatter Formatter, value spanner.GenericColumnValue, toplevel bool) (string, error)
FormatComplexFunc is a function to format spanner.GenericColumnValue. If it returns ErrFallthrough, value will pass through to next step.
type FormatConfig ¶
type FormatConfig struct {
NullString string
FormatArray FormatArrayFunc
FormatStruct FormatStruct
FormatComplexPlugins []FormatComplexFunc
FormatNullable FormatNullableFunc
}
func JSONFormatConfig ¶ added in v0.1.9
func JSONFormatConfig() *FormatConfig
JSONFormatConfig returns a new FormatConfig that produces valid JSON value strings for each Spanner value. Each call returns a fresh instance that the caller may customize.
Each formatted string is a standalone JSON value:
- NULL → null
- BOOL → true / false
- INT64 → 42 (unquoted number)
- FLOAT32/FLOAT64 → 3.14 (NaN/Inf as quoted strings)
- ENUM → 42 (unquoted number, Spanner stores proto enum values as INT64)
- STRING, BYTES, TIMESTAMP, DATE, NUMERIC, PROTO, INTERVAL, UUID → "quoted string"
- JSON column → raw JSON value (passed through)
- ARRAY → [elem1,elem2,...]
- STRUCT → {"field1":val1,"field2":val2,...}
func (*FormatConfig) FormatColumn ¶
func (fc *FormatConfig) FormatColumn(value spanner.GenericColumnValue, toplevel bool) (string, error)
func (*FormatConfig) FormatRow ¶
func (fc *FormatConfig) FormatRow(row *spanner.Row) ([]string, error)
func (*FormatConfig) FormatToplevelColumn ¶
func (fc *FormatConfig) FormatToplevelColumn(value spanner.GenericColumnValue) (string, error)
type FormatNullableFunc ¶
type FormatNullableFunc = func(value NullableValue) (string, error)
type FormatStruct ¶
type FormatStruct struct {
FormatStructField FormatStructFieldFunc
FormatStructParen FormatStructParenFunc
}
type FormatStructFieldFunc ¶
type FormatStructFieldFunc func(fc *FormatConfig, field *sppb.StructType_Field, value *structpb.Value) (string, error)
type FormatStructParenFunc ¶
func NewJSONObjectStructFormatter ¶ added in v0.1.9
func NewJSONObjectStructFormatter(namer UnnamedFieldNamer) FormatStructParenFunc
NewJSONObjectStructFormatter creates a FormatStructParenFunc that formats struct fields as a JSON object with field names as keys. Unnamed fields are assigned names by the provided namer function. If namer is nil, unnamed fields keep empty-string keys (which produces duplicate keys — valid per RFC 8259 but may cause issues with parsers that deduplicate keys). Panics if a non-nil namer returns the same name for different indices (contract violation). Output: {"field1":val1,"field2":val2,...}
type Formatter ¶
type Formatter interface {
FormatColumn(value spanner.GenericColumnValue, toplevel bool) (string, error)
}
type NullableValue ¶
type NullableValue interface {
spanner.NullableValue
fmt.Stringer
}
type UnnamedFieldNamer ¶ added in v0.1.9
UnnamedFieldNamer generates a name for an unnamed field or column. The index argument is a monotonically increasing counter (not necessarily the field's positional index) that may skip values due to collision avoidance. It must return distinct non-empty names for distinct indices. Functions that accept UnnamedFieldNamer (such as NewJSONObjectStructFormatter and FormatRowJSONObject) panic if the namer violates this contract. Pass nil instead of a namer to keep unnamed fields as empty-string keys.