spannerutil

package
v1.111.4 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Error is the default error class for this package.
	Error = errs.Class("spannerutil")
	// ErrMultipleRows is returned when multiple rows are returned from
	// a query that expects no more than one.
	ErrMultipleRows = errs.Class("more than 1 row returned")
)

Functions

func ArrayOf added in v1.111.4

func ArrayOf(typ *spannerpb.Type) *spannerpb.Type

ArrayOf is a convenience method to construct a Spanner protobuf type for an array of elements.

func BuildURL added in v1.109.1

func BuildURL(project string, instance string, database *string) string

BuildURL takes necessary and optional connection string parameters to build a spanner URL.

func BytesType added in v1.111.4

func BytesType() *spannerpb.Type

BytesType is a convenience method to define a Spanner BYTES value.

func CollectRow added in v1.106.1

func CollectRow[T any](iter *spanner.RowIterator, scan func(row *spanner.Row, item *T) error) (r T, _ error)

CollectRow scans a single row into a slice.

func CollectRows added in v1.106.1

func CollectRows[T any](iter *spanner.RowIterator, scan func(row *spanner.Row, item *T) error) (rs []T, _ error)

CollectRows scans each row into a slice.

func CreateDatabase added in v1.109.1

func CreateDatabase(ctx context.Context, projectID, instanceID, databaseName string) error

CreateDatabase creates a schema in spanner with the given name.

func CreateRandomTestingDatabaseName added in v1.109.1

func CreateRandomTestingDatabaseName(n int) string

CreateRandomTestingDatabaseName creates a random schema name string.

func DSNFromURL added in v1.109.1

func DSNFromURL(url string) string

DSNFromURL takes in a Spanner URL and returns back the DSN that is used to connect with Spanner packages.

func DateType added in v1.111.4

func DateType() *spannerpb.Type

DateType is a convenience method to define a Spanner DATE value.

func EncodeBytesToValue added in v1.111.4

func EncodeBytesToValue(bytes []byte) *structpb.Value

EncodeBytesToValue encodes a bytes to what Spanner expects via protobuf.

func EncodeDateToValue added in v1.111.4

func EncodeDateToValue(date civil.Date) *structpb.Value

EncodeDateToValue encodes civil.Date type to what Spanner expects via protobuf.

func EncodeIntToValue added in v1.111.4

func EncodeIntToValue[T constraints.Integer](i T) *structpb.Value

EncodeIntToValue encodes any integer type to what Spanner expects via protobuf.

func EncodeTimeToValue added in v1.111.4

func EncodeTimeToValue(t time.Time) *structpb.Value

EncodeTimeToValue encodes a time.Time to what Spanner expects via protobuf.

func EscapeIdentifier added in v1.109.1

func EscapeIdentifier(s string) string

EscapeIdentifier uses spanner escape characters to escape the given string.

func FieldOf added in v1.111.4

func FieldOf(name string, typ *spannerpb.Type) *spannerpb.StructType_Field

FieldOf is a convenience method to construct a Spanner protobuf type for a field of a struct.

func Int64Type added in v1.111.4

func Int64Type() *spannerpb.Type

Int64Type is a convenience method to define a Spanner INT64 value.

func IsAlreadyExists added in v1.111.4

func IsAlreadyExists(err error) bool

IsAlreadyExists is true if err code is AlreadyExists.

func OpenUnique added in v1.109.1

func OpenUnique(ctx context.Context, connstr string, databasePrefix string) (*dbutil.TempDatabase, error)

OpenUnique opens a spanner database with a temporary unique schema, which will be cleaned up when closed. It is expected that this should normally be used by way of "storj.io/storj/shared/dbutil/tempdb".OpenUnique() instead of calling it directly.

func ParseConnStr added in v1.109.1

func ParseConnStr(full string) (project, instance string, database *string, err error)

ParseConnStr parses a spanner connection string to return the relevant pieces of the connection.

func StringType added in v1.111.4

func StringType() *spannerpb.Type

StringType is a convenience method to define a Spanner STRING value.

func StructOf added in v1.111.4

func StructOf(fields ...*spannerpb.StructType_Field) *spannerpb.Type

StructOf is a convenience method to construct a Spanner protobuf type for a struct.

func TimestampType added in v1.111.4

func TimestampType() *spannerpb.Type

TimestampType is a convenience method to define a Spanner STRING value.

Types

type EmulatorAdmin added in v1.109.1

type EmulatorAdmin struct {
	HostPort  string
	Instances *instance.InstanceAdminClient
	Databases *database.DatabaseAdminClient
}

EmulatorAdmin provides facilities to communicate with the Spanner Emulator to create new instances and databases.

func OpenEmulatorAdmin added in v1.109.1

func OpenEmulatorAdmin(ctx context.Context, hostport string) (*EmulatorAdmin, error)

OpenEmulatorAdmin creates a new emulator admin that uses the specified endpoint.

func (*EmulatorAdmin) Close added in v1.109.1

func (admin *EmulatorAdmin) Close() error

Close closes the underlying clients.

func (*EmulatorAdmin) CreateDatabase added in v1.109.1

func (admin *EmulatorAdmin) CreateDatabase(ctx context.Context, projectID, instanceID, databaseID string, ddls ...string) error

CreateDatabase creates a new database with the specified name.

func (*EmulatorAdmin) CreateInstance added in v1.109.1

func (admin *EmulatorAdmin) CreateInstance(ctx context.Context, projectID, instanceID string) error

CreateInstance creates a new instance with the specified name.

func (*EmulatorAdmin) DeleteInstance added in v1.109.1

func (admin *EmulatorAdmin) DeleteInstance(ctx context.Context, projectID, instanceID string) error

DeleteInstance deletes an instance with the specified name.

func (*EmulatorAdmin) DialDatabase added in v1.109.1

func (admin *EmulatorAdmin) DialDatabase(ctx context.Context, projectID, instanceID, databaseID string) (*spanner.Client, error)

DialDatabase creates a new connection to the spanner instance.

func (*EmulatorAdmin) DropDatabase added in v1.109.1

func (admin *EmulatorAdmin) DropDatabase(ctx context.Context, projectID, instanceID, databaseID string) error

DropDatabase deletes the specified database.

type IntValueDecoder

type IntValueDecoder[T inty] struct {
	// contains filtered or unexported fields
}

IntValueDecoder is a type wrapping an int pointer so it can decode integer values from Spanner directly (Spanner prefers to work only in int64s).

func Int

func Int[T inty](val *T) IntValueDecoder[T]

Int wraps a pointer to an int-based type in a type that can be decoded directly from Spanner.

In general, it is preferable to add EncodeSpanner/DecodeSpanner methods to our specialized int types, but this can be used for types we don't own or otherwise can't put methods on.

func (IntValueDecoder[T]) DecodeSpanner

func (s IntValueDecoder[T]) DecodeSpanner(input any) error

DecodeSpanner decodes a value from a Spanner-stored type to the appropriate int type. It implements spanner.Decoder.

Jump to

Keyboard shortcuts

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