spannerutil

package
v1.109.0-rc Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Error = errs.Class("spannerutil")

Error is error class for this package.

Functions

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 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 EscapeIdentifier added in v1.109.1

func EscapeIdentifier(s string) string

EscapeIdentifier uses spanner escape characters to escape the given string.

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.

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