Documentation
¶
Overview ¶
Package spantype formats Cloud Spanner google.spanner.v1.Type values with multiple verbosity levels for logs, errors, and debugging output. Dialect sppb.Type.TypeAnnotation values (for example PostgreSQL PG_NUMERIC) are controlled by TypeAnnotationMode inside FormatOption.
Index ¶
- Variables
- func FormatProtoEnum(typ *sppb.Type, mode ProtoEnumMode) string
- func FormatStructFields(fields []*sppb.StructType_Field, opts FormatOption) string
- func FormatType(typ *sppb.Type, opts FormatOption) string
- func FormatTypeCode(code sppb.TypeCode, mode UnknownMode) string
- func FormatTypeMoreVerbose(typ *sppb.Type) string
- func FormatTypeNormal(typ *sppb.Type) string
- func FormatTypeSimple(typ *sppb.Type) string
- func FormatTypeSimplest(typ *sppb.Type) string
- func FormatTypeVerbose(typ *sppb.Type) string
- type ArrayMode
- type FormatOption
- type ProtoEnumMode
- type StructMode
- type TypeAnnotationMode
- type UnknownMode
Constants ¶
This section is empty.
Variables ¶
var ( // FormatOptionSimplest is a FormatOption for FormatTypeSimplest. FormatOptionSimplest = FormatOption{ Struct: StructModeBase, Proto: ProtoEnumModeBase, Enum: ProtoEnumModeBase, Array: ArrayModeBase, Unknown: UnknownModeTypeCode, } // FormatOptionSimple is a FormatOption for FormatTypeSimple. FormatOptionSimple = FormatOption{ Struct: StructModeBase, Proto: ProtoEnumModeLeaf, Enum: ProtoEnumModeLeaf, Array: ArrayModeRecursive, Unknown: UnknownModeUnknown, } // FormatOptionNormal is a FormatOption for FormatTypeNormal. FormatOptionNormal = FormatOption{ Struct: StructModeRecursive, Proto: ProtoEnumModeLeaf, Enum: ProtoEnumModeLeaf, Array: ArrayModeRecursive, Unknown: UnknownModeVerbose, } // FormatOptionVerbose is a FormatOption for FormatTypeVerbose. FormatOptionVerbose = FormatOption{ Struct: StructModeRecursiveWithName, Proto: ProtoEnumModeFull, Enum: ProtoEnumModeFull, Array: ArrayModeRecursive, Unknown: UnknownModeVerbose, } // FormatOptionMoreVerbose is a FormatOption for FormatTypeMoreVerbose. FormatOptionMoreVerbose = FormatOption{ Struct: StructModeRecursiveWithName, Proto: ProtoEnumModeFullWithKind, Enum: ProtoEnumModeFullWithKind, Array: ArrayModeRecursive, Unknown: UnknownModeVerbose, } )
Functions ¶
func FormatProtoEnum ¶ added in v0.2.0
func FormatProtoEnum(typ *sppb.Type, mode ProtoEnumMode) string
FormatProtoEnum formats `PROTO` or `ENUM` type using ProtoEnumMode. It panics when the input type is not `PROTO` or `ENUM`.
func FormatStructFields ¶
func FormatStructFields(fields []*sppb.StructType_Field, opts FormatOption) string
FormatStructFields formats Cloud Spanner struct fields or `metadata.rowType` using the given FormatOption.
func FormatType ¶
func FormatType(typ *sppb.Type, opts FormatOption) string
FormatType formats Cloud Spanner type using the given FormatOption. [FormatOption.TypeAnnotation] selects whether sppb.Type.TypeAnnotation is omitted, appended in parentheses after the base type, or used as the primary label (see TypeAnnotationMode).
func FormatTypeCode ¶ added in v0.2.0
func FormatTypeCode(code sppb.TypeCode, mode UnknownMode) string
FormatTypeCode formats sppb.TypeCode, but it formats unknown type code as `UNKNOWN(int32(code))`. e.g. `UNKNOWN(-1)`
func FormatTypeMoreVerbose ¶ added in v0.3.0
FormatTypeMoreVerbose formats Cloud Spanner type as more verbose format. e.g. `INT64`, `ARRAY<INT64>`, `PROTO<examples.ProtoType>`, `ENUM<examples.EnumType>`, `STRUCT<n INT64>`
func FormatTypeNormal ¶
FormatTypeNormal formats Cloud Spanner type as normal format. e.g. `INT64`, `ARRAY<INT64>`, `ProtoType`, `EnumType`, `STRUCT<INT64>`
func FormatTypeSimple ¶
FormatTypeSimple formats Cloud Spanner type as simple format. e.g. `INT64`, `ARRAY<INT64>`, `ProtoType`, `EnumType`, `STRUCT`
func FormatTypeSimplest ¶
FormatTypeSimplest formats Cloud Spanner type as simplest format. e.g. `INT64`, `ARRAY`, `PROTO`, `ENUM`, `STRUCT`
func FormatTypeVerbose ¶
FormatTypeVerbose formats Cloud Spanner type as verbose format. e.g. `INT64`, `ARRAY<INT64>`, `examples.ProtoType`, `examples.EnumType`, `STRUCT<n INT64>`
Types ¶
type ArrayMode ¶
type ArrayMode int
ArrayMode controls how ARRAY types are rendered by selecting either base or recursive element rendering.
type FormatOption ¶
type FormatOption struct {
// Struct controls STRUCT formatting.
Struct StructMode
// Proto controls PROTO formatting.
Proto ProtoEnumMode
// Enum controls ENUM formatting.
Enum ProtoEnumMode
// Array controls ARRAY formatting.
Array ArrayMode
// Unknown controls formatting for unknown type codes.
Unknown UnknownMode
// TypeAnnotation controls how dialect TypeAnnotation is combined with the base type.
TypeAnnotation TypeAnnotationMode
}
FormatOption is an option for FormatType, and FormatStructFields.
Callers building their own values should use keyed struct literals (e.g. FormatOption{Struct: ..., Proto: ...}) so that new fields can be added in minor releases without breaking compilation. Positional literals are fragile.
type ProtoEnumMode ¶ added in v0.2.0
type ProtoEnumMode int
ProtoEnumMode controls how PROTO and ENUM types are rendered by selecting base, leaf, full-name, or explicit-kind output.
const ( // ProtoEnumModeBase formats `PROTO` and `ENUM` type as `PROTO` and `ENUM`. ProtoEnumModeBase ProtoEnumMode = iota // ProtoEnumModeLeaf formats `PROTO` and `ENUM` type without package name. e.g. `ProtoType`, `EnumType` ProtoEnumModeLeaf // ProtoEnumModeFull formats `PROTO` and `ENUM` type as full qualified name. e.g. `examples.ProtoType`, `examples.EnumType` ProtoEnumModeFull // ProtoEnumModeLeafWithKind formats `PROTO` and `ENUM` type without package name with kind. // e.g. `PROTO<ProtoType>`, `ENUM<EnumType>` ProtoEnumModeLeafWithKind // ProtoEnumModeFullWithKind formats `PROTO` and `ENUM` type as full qualified name with kind. // e.g. `PROTO<examples.ProtoType>`, `ENUM<examples.EnumType>`. // Note: It should be same format with `INFORMATION_SCHEMA.COLUMNS.SPANNER_TYPE`. ProtoEnumModeFullWithKind )
type StructMode ¶
type StructMode int
StructMode controls how STRUCT types are rendered by selecting one of StructModeBase, StructModeRecursive, or StructModeRecursiveWithName.
const ( // StructModeBase formats `STRUCT` type as `STRUCT`. StructModeBase StructMode = iota // StructModeRecursive formats `STRUCT` type with field types. e.g. `STRUCT<INT64, STRUCT<INT64>>` StructModeRecursive // StructModeRecursiveWithName formats `STRUCT` type with field types with field name. e.g. `STRUCT<n INT64, s STRUCT<n INT64>>` StructModeRecursiveWithName )
type TypeAnnotationMode ¶ added in v0.3.11
type TypeAnnotationMode int
TypeAnnotationMode controls how sppb.Type.TypeAnnotation is rendered for simple and container types (recursively for ARRAY and STRUCT fields).
const ( // TypeAnnotationModeSuffix is the default (zero value): append a parenthetical // annotation when set, e.g. `NUMERIC(PG_NUMERIC)`. TypeAnnotationModeSuffix TypeAnnotationMode = iota // TypeAnnotationModeOmit ignores TypeAnnotation and formats the base type only, e.g. `NUMERIC`. TypeAnnotationModeOmit // TypeAnnotationModePrimary uses the annotation as the displayed type label when non-UNSPECIFIED, // e.g. `PG_NUMERIC` instead of `NUMERIC` or `NUMERIC(PG_NUMERIC)`. TypeAnnotationModePrimary )
type UnknownMode ¶ added in v0.3.0
type UnknownMode int
UnknownMode controls how unknown type codes are rendered by selecting UNKNOWN, the raw numeric code, a verbose form, or panic behavior.
const ( // UnknownModeUnknown formats unknown type code as `UNKNOWN` UnknownModeUnknown UnknownMode = iota // UnknownModeTypeCode formats unknown type code as e.g. `-1` UnknownModeTypeCode // UnknownModeVerbose formats unknown type code as `UNKNOWN(int32(code))` as e.g. `UNKNOWN(-1)` UnknownModeVerbose // UnknownModePanic panics when type code is unknown. UnknownModePanic )
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
spantype
command
|
|
|
Package typector provides small constructor helpers for building Cloud Spanner google.spanner.v1.Type values and struct fields in tests and callers.
|
Package typector provides small constructor helpers for building Cloud Spanner google.spanner.v1.Type values and struct fields in tests and callers. |