spantype

package module
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 4 Imported by: 3

README

spantype

spantype package provides format functions for google.spanner.v1.Type with various format options.

Go Reference

./cmd/spantype is a example application.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

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

func FormatTypeMoreVerbose(typ *sppb.Type) string

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

func FormatTypeNormal(typ *sppb.Type) string

FormatTypeNormal formats Cloud Spanner type as normal format. e.g. `INT64`, `ARRAY<INT64>`, `ProtoType`, `EnumType`, `STRUCT<INT64>`

func FormatTypeSimple

func FormatTypeSimple(typ *sppb.Type) string

FormatTypeSimple formats Cloud Spanner type as simple format. e.g. `INT64`, `ARRAY<INT64>`, `ProtoType`, `EnumType` `STRUCT`

func FormatTypeSimplest

func FormatTypeSimplest(typ *sppb.Type) string

FormatTypeSimplest formats Cloud Spanner type as simplest format. e.g. `INT64`, `ARRAY, `PROTO`, `ENUM` `STRUCT`

func FormatTypeVerbose

func FormatTypeVerbose(typ *sppb.Type) string

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
const (
	// ArrayModeBase formats `ARRAY` type as `ARRAY`
	ArrayModeBase ArrayMode = iota
	// ArrayModeRecursive formats `ARRAY` type with element type. e.g. `ARRAY<INT64>`
	ArrayModeRecursive
)

type FormatOption

type FormatOption struct {
	Struct  StructMode
	Proto   ProtoEnumMode
	Enum    ProtoEnumMode
	Array   ArrayMode
	Unknown UnknownMode
}

FormatOption is a option for FormatType, and FormatStructFields.

type ProtoEnumMode added in v0.2.0

type ProtoEnumMode int
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
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 UnknownMode added in v0.3.0

type UnknownMode int
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

Jump to

Keyboard shortcuts

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