Documentation ¶
Index ¶
- Variables
- func ArrayOf(typ *spannerpb.Type) *spannerpb.Type
- func BuildURL(project string, instance string, database *string) string
- func BytesType() *spannerpb.Type
- func CollectRow[T any](iter *spanner.RowIterator, scan func(row *spanner.Row, item *T) error) (r T, _ error)
- func CollectRows[T any](iter *spanner.RowIterator, scan func(row *spanner.Row, item *T) error) (rs []T, _ error)
- func CreateDatabase(ctx context.Context, projectID, instanceID, databaseName string) error
- func CreateRandomTestingDatabaseName(n int) string
- func DSNFromURL(url string) string
- func DateType() *spannerpb.Type
- func EncodeBytesToValue(bytes []byte) *structpb.Value
- func EncodeDateToValue(date civil.Date) *structpb.Value
- func EncodeIntToValue[T constraints.Integer](i T) *structpb.Value
- func EncodeTimeToValue(t time.Time) *structpb.Value
- func EscapeIdentifier(s string) string
- func FieldOf(name string, typ *spannerpb.Type) *spannerpb.StructType_Field
- func Int64Type() *spannerpb.Type
- func IsAlreadyExists(err error) bool
- func OpenUnique(ctx context.Context, connstr string, databasePrefix string) (*dbutil.TempDatabase, error)
- func ParseConnStr(full string) (project, instance string, database *string, err error)
- func StringType() *spannerpb.Type
- func StructOf(fields ...*spannerpb.StructType_Field) *spannerpb.Type
- func TimestampType() *spannerpb.Type
- type EmulatorAdmin
- func (admin *EmulatorAdmin) Close() error
- func (admin *EmulatorAdmin) CreateDatabase(ctx context.Context, projectID, instanceID, databaseID string, ddls ...string) error
- func (admin *EmulatorAdmin) CreateInstance(ctx context.Context, projectID, instanceID string) error
- func (admin *EmulatorAdmin) DeleteInstance(ctx context.Context, projectID, instanceID string) error
- func (admin *EmulatorAdmin) DialDatabase(ctx context.Context, projectID, instanceID, databaseID string) (*spanner.Client, error)
- func (admin *EmulatorAdmin) DropDatabase(ctx context.Context, projectID, instanceID, databaseID string) error
- type IntValueDecoder
Constants ¶
This section is empty.
Variables ¶
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
ArrayOf is a convenience method to construct a Spanner protobuf type for an array of elements.
func BuildURL ¶ added in v1.109.1
BuildURL takes necessary and optional connection string parameters to build a spanner URL.
func BytesType ¶ added in v1.111.4
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
CreateDatabase creates a schema in spanner with the given name.
func CreateRandomTestingDatabaseName ¶ added in v1.109.1
CreateRandomTestingDatabaseName creates a random schema name string.
func DSNFromURL ¶ added in v1.109.1
DSNFromURL takes in a Spanner URL and returns back the DSN that is used to connect with Spanner packages.
func EncodeBytesToValue ¶ added in v1.111.4
EncodeBytesToValue encodes a bytes to what Spanner expects via protobuf.
func EncodeDateToValue ¶ added in v1.111.4
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
EncodeTimeToValue encodes a time.Time to what Spanner expects via protobuf.
func EscapeIdentifier ¶ added in v1.109.1
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
Int64Type is a convenience method to define a Spanner INT64 value.
func IsAlreadyExists ¶ added in v1.111.4
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
ParseConnStr parses a spanner connection string to return the relevant pieces of the connection.
func StringType ¶ added in v1.111.4
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
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.