Documentation ¶
Index ¶
- Variables
- func ArrayOf(typ *spannerpb.Type) *spannerpb.Type
- 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 CreateRandomTestingDatabaseName(n int) string
- func DateType() *spannerpb.Type
- func DialDatabase(ctx context.Context, params ConnParams) (*spanner.Client, error)
- func EncodeBytesToValue(bytes []byte) *structpb.Value
- func EncodeDateToValue(date civil.Date) *structpb.Value
- func EncodeFloat64ToValue(i float64) *structpb.Value
- func EncodeIntToValue[T constraints.Integer](i T) *structpb.Value
- func EncodeStringToValue(str string) *structpb.Value
- func EncodeTimeToValue(t time.Time) *structpb.Value
- func FieldOf(name string, typ *spannerpb.Type) *spannerpb.StructType_Field
- func Float64Type() *spannerpb.Type
- func Int64Type() *spannerpb.Type
- func IsAlreadyExists(err error) bool
- func OpenUnique(ctx context.Context, connstr string, databasePrefix string) (*dbutil.TempDatabase, error)
- func SplitDDL(ddls string) []string
- func StringType() *spannerpb.Type
- func StructOf(fields ...*spannerpb.StructType_Field) *spannerpb.Type
- func TimestampType() *spannerpb.Type
- func TupleGreaterThanSQL(tup1, tup2 []string, orEqual bool) (string, error)
- type ConnParams
- func (params *ConnParams) AllDefined() bool
- func (params *ConnParams) ClientOptions() (options []option.ClientOption)
- func (params *ConnParams) ConnStr() string
- func (params *ConnParams) DatabasePath() string
- func (params *ConnParams) GoSqlSpannerConnStr() string
- func (params *ConnParams) InstancePath() string
- func (params *ConnParams) ProjectPath() string
- type EmulatorAdmin
- func (admin *EmulatorAdmin) Close() error
- func (admin *EmulatorAdmin) CreateDatabase(ctx context.Context, params ConnParams, ddls ...string) error
- func (admin *EmulatorAdmin) CreateInstance(ctx context.Context, params ConnParams) error
- func (admin *EmulatorAdmin) DeleteInstance(ctx context.Context, params ConnParams) error
- func (admin *EmulatorAdmin) DropDatabase(ctx context.Context, params ConnParams) error
- type EphemeralDB
- 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 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 query. It returns errors if the iterator doesn't have exactly one row.
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 CreateRandomTestingDatabaseName ¶ added in v1.109.1
CreateRandomTestingDatabaseName creates a random schema name string.
func DialDatabase ¶ added in v1.115.1
DialDatabase creates a new connection to the spanner instance.
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 EncodeFloat64ToValue ¶ added in v1.112.2
EncodeFloat64ToValue encodes any float64 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 EncodeStringToValue ¶ added in v1.112.2
EncodeStringToValue encodes string 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 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 Float64Type ¶ added in v1.112.2
Float64Type is a convenience method to define a Spanner FLOAT64 value.
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 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.
func TupleGreaterThanSQL ¶ added in v1.112.2
TupleGreaterThanSQL returns a constructed SQL expression equivalent to a tuple comparison (e.g. (tup1[0], tup1[1], ...) > (tup2[0], tup2[1], ...)).
If orEqual is true, the returned expression will compare the tuples as "greater than or equal" (>=) instead of "greater than" (>).
This is necessary because Spanner does not support comparison of tuples, except with equality (=).
Example:
(a, b, c) >= (d, e, f)
becomes
TupleGreaterThanSQL([]string{"a", "b", "c"}, []string{"d", "e", "f"}, true)
which returns
"((a > d) OR (a = d AND b > e) OR (a = d AND b = e AND c >= f))"
Types ¶
type ConnParams ¶ added in v1.115.1
ConnParams contains arguments from a spanner URL.
func ParseConnStr ¶ added in v1.109.1
func ParseConnStr(full string) (params ConnParams, err error)
ParseConnStr parses a spanner connection string to return the relevant pieces of the connection.
func (*ConnParams) AllDefined ¶ added in v1.115.1
func (params *ConnParams) AllDefined() bool
AllDefined returns whether project, instance and database are all defined.
func (*ConnParams) ClientOptions ¶ added in v1.115.1
func (params *ConnParams) ClientOptions() (options []option.ClientOption)
ClientOptions returns arguments for dialing spanner clients.
func (*ConnParams) ConnStr ¶ added in v1.115.1
func (params *ConnParams) ConnStr() string
ConnStr returns connection string.
func (*ConnParams) DatabasePath ¶ added in v1.115.1
func (params *ConnParams) DatabasePath() string
DatabasePath returns "projects/<Project>/instances/<Instance>/databases/<Database>".
func (*ConnParams) GoSqlSpannerConnStr ¶ added in v1.115.1
func (params *ConnParams) GoSqlSpannerConnStr() string
GoSqlSpannerConnStr returns connection string for github.com/googleapis/go-sql-spanner.
func (*ConnParams) InstancePath ¶ added in v1.115.1
func (params *ConnParams) InstancePath() string
InstancePath returns "projects/<Project>/instances/<Instance>".
func (*ConnParams) ProjectPath ¶ added in v1.115.1
func (params *ConnParams) ProjectPath() string
ProjectPath returns "projects/<Project>".
type EmulatorAdmin ¶ added in v1.109.1
type EmulatorAdmin struct { Params ConnParams 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(params ConnParams) *EmulatorAdmin
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, params ConnParams, 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, params ConnParams) 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, params ConnParams) error
DeleteInstance deletes an instance with the specified name.
func (*EmulatorAdmin) DropDatabase ¶ added in v1.109.1
func (admin *EmulatorAdmin) DropDatabase(ctx context.Context, params ConnParams) error
DropDatabase deletes the specified database.
type EphemeralDB ¶ added in v1.115.1
type EphemeralDB struct { Params ConnParams // contains filtered or unexported fields }
EphemeralDB manages lifecycle of a temporary database.
func CreateEphemeralDB ¶ added in v1.115.1
func CreateEphemeralDB(ctx context.Context, connstr string, databasePrefix string, ddls ...string) (*EphemeralDB, error)
CreateEphemeralDB automatically creates instance and database as necessary.
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.