musicdb

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlbumsKey

type AlbumsKey struct {
	SingerId int64
	AlbumId  int64
}

func (AlbumsKey) BoolExpr

func (k AlbumsKey) BoolExpr() spansql.BoolExpr

func (AlbumsKey) Delete

func (k AlbumsKey) Delete() *spanner.Mutation

func (AlbumsKey) Order

func (AlbumsKey) Order() []spansql.Order

func (AlbumsKey) SpannerKey

func (k AlbumsKey) SpannerKey() spanner.Key

func (AlbumsKey) SpannerKeySet

func (k AlbumsKey) SpannerKeySet() spanner.KeySet

type AlbumsRow

type AlbumsRow struct {
	SingerId   int64              `spanner:"SingerId"`
	AlbumId    int64              `spanner:"AlbumId"`
	AlbumTitle spanner.NullString `spanner:"AlbumTitle"`
	Songs      []*SongsRow        `spanner:"Songs"`
}

func (*AlbumsRow) ColumnExprs

func (*AlbumsRow) ColumnExprs() []spansql.Expr

func (*AlbumsRow) ColumnIDs

func (*AlbumsRow) ColumnIDs() []spansql.ID

func (*AlbumsRow) ColumnNames

func (*AlbumsRow) ColumnNames() []string

func (*AlbumsRow) Key

func (r *AlbumsRow) Key() AlbumsKey

func (*AlbumsRow) Mutate added in v0.15.0

func (r *AlbumsRow) Mutate() (string, []string, []interface{})

func (*AlbumsRow) MutateColumns added in v0.15.0

func (r *AlbumsRow) MutateColumns(columns []string) (string, []string, []interface{})

func (*AlbumsRow) MutatePresentColumns added in v0.31.0

func (r *AlbumsRow) MutatePresentColumns() (string, []string, []interface{})

func (*AlbumsRow) UnmarshalSpannerRow

func (r *AlbumsRow) UnmarshalSpannerRow(row *spanner.Row) error

func (*AlbumsRow) Validate

func (r *AlbumsRow) Validate() error

type AlbumsRowIterator

type AlbumsRowIterator interface {
	Next() (*AlbumsRow, error)
	Do(f func(row *AlbumsRow) error) error
	Stop()
}

type AlbumsTableDescriptor

type AlbumsTableDescriptor interface {
	TableName() string
	TableID() spansql.ID
	ColumnNames() []string
	ColumnIDs() []spansql.ID
	ColumnExprs() []spansql.Expr
	SingerId() ColumnDescriptor
	AlbumId() ColumnDescriptor
	AlbumTitle() ColumnDescriptor
}

type BatchGetAlbumsRowsQuery added in v0.16.0

type BatchGetAlbumsRowsQuery struct {
	Keys  []AlbumsKey
	Songs bool
}

type BatchGetSingersRowsQuery added in v0.16.0

type BatchGetSingersRowsQuery struct {
	Keys   []SingersKey
	Albums bool
	Songs  bool
}

type BatchGetSongsRowsQuery added in v0.16.0

type BatchGetSongsRowsQuery struct {
	Keys []SongsKey
}

type ColumnDescriptor

type ColumnDescriptor interface {
	ColumnID() spansql.ID
	ColumnName() string
	ColumnType() spansql.Type
	NotNull() bool
	AllowCommitTimestamp() bool
}

type DatabaseDescriptor

type DatabaseDescriptor interface {
	Singers() SingersTableDescriptor
	Albums() AlbumsTableDescriptor
	Songs() SongsTableDescriptor
}

func Descriptor

func Descriptor() DatabaseDescriptor

type GetAlbumsRowQuery added in v0.16.0

type GetAlbumsRowQuery struct {
	Key   AlbumsKey
	Songs bool
}

type GetSingersRowQuery added in v0.16.0

type GetSingersRowQuery struct {
	Key    SingersKey
	Albums bool
	Songs  bool
}

type GetSongsRowQuery added in v0.16.0

type GetSongsRowQuery struct {
	Key SongsKey
}

type ListAlbumsRowsQuery added in v0.16.0

type ListAlbumsRowsQuery struct {
	Where  spansql.BoolExpr
	Order  []spansql.Order
	Limit  int32
	Offset int64
	Params map[string]interface{}
	Songs  bool
}

type ListSingersRowsQuery added in v0.16.0

type ListSingersRowsQuery struct {
	Where  spansql.BoolExpr
	Order  []spansql.Order
	Limit  int32
	Offset int64
	Params map[string]interface{}
	Albums bool
	Songs  bool
}

type ListSongsRowsQuery added in v0.16.0

type ListSongsRowsQuery struct {
	Where  spansql.BoolExpr
	Order  []spansql.Order
	Limit  int32
	Offset int64
	Params map[string]interface{}
}

type ReadTransaction added in v0.15.0

type ReadTransaction struct {
	Tx SpannerReadTransaction
}

func Query added in v0.15.0

Example (Get)
package main

import (
	"context"

	"cloud.google.com/go/spanner"
	"go.einride.tech/spanner-aip/internal/examples/musicdb"
)

func main() {
	ctx := context.Background()
	client, err := spanner.NewClient(
		ctx, "projects/<PROJECT>/instances/<INSTANCE>/databases/<DATABASE>",
	)
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	singer, err := musicdb.Query(client.Single()).GetSingersRow(ctx, musicdb.GetSingersRowQuery{
		Key: musicdb.SingersKey{SingerId: 42},
	})
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	_ = singer // TODO: Use singer.
}
Output:

Example (GetMultiple)
package main

import (
	"context"

	"cloud.google.com/go/spanner"
	"go.einride.tech/spanner-aip/internal/examples/musicdb"
)

func main() {
	ctx := context.Background()
	client, err := spanner.NewClient(
		ctx, "projects/<PROJECT>/instances/<INSTANCE>/databases/<DATABASE>",
	)
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	tx := client.ReadOnlyTransaction()
	defer tx.Close()
	singer, err := musicdb.Query(tx).GetSingersRow(ctx, musicdb.GetSingersRowQuery{
		Key: musicdb.SingersKey{SingerId: 42},
	})
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	album, err := musicdb.Query(tx).GetAlbumsRow(ctx, musicdb.GetAlbumsRowQuery{
		Key: musicdb.AlbumsKey{SingerId: 42, AlbumId: 24},
	})
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	_ = singer // TODO: Use singer.
	_ = album  // TODO: Use album.
}
Output:

Example (List)
package main

import (
	"context"

	"cloud.google.com/go/spanner"
	"cloud.google.com/go/spanner/spansql"
	"go.einride.tech/spanner-aip/internal/examples/musicdb"
)

func main() {
	ctx := context.Background()
	client, err := spanner.NewClient(
		ctx, "projects/<PROJECT>/instances/<INSTANCE>/databases/<DATABASE>",
	)
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	// SELECT * FROM Singers
	// WHERE LastName = "Sinatra"
	// ORDER BY FirstName DESC
	// LIMIT 5
	// OFFSET 10
	if err := musicdb.Query(client.Single()).ListSingersRows(ctx, musicdb.ListSingersRowsQuery{
		Where: spansql.ComparisonOp{
			Op:  spansql.Eq,
			LHS: musicdb.Descriptor().Singers().LastName().ColumnID(),
			RHS: spansql.StringLiteral("Sinatra"),
		},
		Order: []spansql.Order{
			{Expr: musicdb.Descriptor().Singers().FirstName().ColumnID(), Desc: true},
		},
		Limit:  5,
		Offset: 10,
	}).Do(func(singer *musicdb.SingersRow) error {
		_ = singer // TODO: Use singer.
		return nil
	}); err != nil {
		panic(err) // TODO: Handle error.
	}
}
Output:

func (ReadTransaction) BatchGetAlbumsRows added in v0.15.0

func (t ReadTransaction) BatchGetAlbumsRows(
	ctx context.Context,
	query BatchGetAlbumsRowsQuery,
) (map[AlbumsKey]*AlbumsRow, error)

func (ReadTransaction) BatchGetSingersRows added in v0.15.0

func (t ReadTransaction) BatchGetSingersRows(
	ctx context.Context,
	query BatchGetSingersRowsQuery,
) (map[SingersKey]*SingersRow, error)

func (ReadTransaction) BatchGetSongsRows added in v0.15.0

func (t ReadTransaction) BatchGetSongsRows(
	ctx context.Context,
	query BatchGetSongsRowsQuery,
) (map[SongsKey]*SongsRow, error)

func (ReadTransaction) GetAlbumsRow added in v0.15.0

func (t ReadTransaction) GetAlbumsRow(
	ctx context.Context,
	query GetAlbumsRowQuery,
) (*AlbumsRow, error)

func (ReadTransaction) GetSingersRow added in v0.15.0

func (t ReadTransaction) GetSingersRow(
	ctx context.Context,
	query GetSingersRowQuery,
) (*SingersRow, error)

func (ReadTransaction) GetSongsRow added in v0.15.0

func (t ReadTransaction) GetSongsRow(
	ctx context.Context,
	query GetSongsRowQuery,
) (*SongsRow, error)

func (ReadTransaction) ListAlbumsRows added in v0.15.0

func (t ReadTransaction) ListAlbumsRows(
	ctx context.Context,
	query ListAlbumsRowsQuery,
) AlbumsRowIterator

func (ReadTransaction) ListSingersRows added in v0.15.0

func (t ReadTransaction) ListSingersRows(
	ctx context.Context,
	query ListSingersRowsQuery,
) SingersRowIterator

func (ReadTransaction) ListSongsRows added in v0.15.0

func (t ReadTransaction) ListSongsRows(
	ctx context.Context,
	query ListSongsRowsQuery,
) SongsRowIterator

func (ReadTransaction) ReadAlbumsRows added in v0.15.0

func (t ReadTransaction) ReadAlbumsRows(
	ctx context.Context,
	keySet spanner.KeySet,
) AlbumsRowIterator

func (ReadTransaction) ReadSingersRows added in v0.15.0

func (t ReadTransaction) ReadSingersRows(
	ctx context.Context,
	keySet spanner.KeySet,
) SingersRowIterator

func (ReadTransaction) ReadSongsRows added in v0.15.0

func (t ReadTransaction) ReadSongsRows(
	ctx context.Context,
	keySet spanner.KeySet,
) SongsRowIterator

type SingersKey

type SingersKey struct {
	SingerId int64
}

func (SingersKey) BoolExpr

func (k SingersKey) BoolExpr() spansql.BoolExpr

func (SingersKey) Delete

func (k SingersKey) Delete() *spanner.Mutation

func (SingersKey) Order

func (SingersKey) Order() []spansql.Order

func (SingersKey) SpannerKey

func (k SingersKey) SpannerKey() spanner.Key

func (SingersKey) SpannerKeySet

func (k SingersKey) SpannerKeySet() spanner.KeySet

type SingersRow

type SingersRow struct {
	SingerId   int64              `spanner:"SingerId"`
	FirstName  spanner.NullString `spanner:"FirstName"`
	LastName   spanner.NullString `spanner:"LastName"`
	SingerInfo []uint8            `spanner:"SingerInfo"`
	Albums     []*AlbumsRow       `spanner:"Albums"`
}

func (*SingersRow) ColumnExprs

func (*SingersRow) ColumnExprs() []spansql.Expr

func (*SingersRow) ColumnIDs

func (*SingersRow) ColumnIDs() []spansql.ID

func (*SingersRow) ColumnNames

func (*SingersRow) ColumnNames() []string

func (*SingersRow) Key

func (r *SingersRow) Key() SingersKey

func (*SingersRow) Mutate added in v0.15.0

func (r *SingersRow) Mutate() (string, []string, []interface{})

func (*SingersRow) MutateColumns added in v0.15.0

func (r *SingersRow) MutateColumns(columns []string) (string, []string, []interface{})

func (*SingersRow) MutatePresentColumns added in v0.31.0

func (r *SingersRow) MutatePresentColumns() (string, []string, []interface{})

func (*SingersRow) UnmarshalSpannerRow

func (r *SingersRow) UnmarshalSpannerRow(row *spanner.Row) error

func (*SingersRow) Validate

func (r *SingersRow) Validate() error

type SingersRowIterator

type SingersRowIterator interface {
	Next() (*SingersRow, error)
	Do(f func(row *SingersRow) error) error
	Stop()
}

type SingersTableDescriptor

type SingersTableDescriptor interface {
	TableName() string
	TableID() spansql.ID
	ColumnNames() []string
	ColumnIDs() []spansql.ID
	ColumnExprs() []spansql.Expr
	SingerId() ColumnDescriptor
	FirstName() ColumnDescriptor
	LastName() ColumnDescriptor
	SingerInfo() ColumnDescriptor
}

type SongsKey

type SongsKey struct {
	SingerId int64
	AlbumId  int64
	TrackId  int64
}

func (SongsKey) BoolExpr

func (k SongsKey) BoolExpr() spansql.BoolExpr

func (SongsKey) Delete

func (k SongsKey) Delete() *spanner.Mutation

func (SongsKey) Order

func (SongsKey) Order() []spansql.Order

func (SongsKey) SpannerKey

func (k SongsKey) SpannerKey() spanner.Key

func (SongsKey) SpannerKeySet

func (k SongsKey) SpannerKeySet() spanner.KeySet

type SongsRow

type SongsRow struct {
	SingerId int64              `spanner:"SingerId"`
	AlbumId  int64              `spanner:"AlbumId"`
	TrackId  int64              `spanner:"TrackId"`
	SongName spanner.NullString `spanner:"SongName"`
}

func (*SongsRow) ColumnExprs

func (*SongsRow) ColumnExprs() []spansql.Expr

func (*SongsRow) ColumnIDs

func (*SongsRow) ColumnIDs() []spansql.ID

func (*SongsRow) ColumnNames

func (*SongsRow) ColumnNames() []string

func (*SongsRow) Key

func (r *SongsRow) Key() SongsKey

func (*SongsRow) Mutate added in v0.15.0

func (r *SongsRow) Mutate() (string, []string, []interface{})

func (*SongsRow) MutateColumns added in v0.15.0

func (r *SongsRow) MutateColumns(columns []string) (string, []string, []interface{})

func (*SongsRow) MutatePresentColumns added in v0.31.0

func (r *SongsRow) MutatePresentColumns() (string, []string, []interface{})

func (*SongsRow) UnmarshalSpannerRow

func (r *SongsRow) UnmarshalSpannerRow(row *spanner.Row) error

func (*SongsRow) Validate

func (r *SongsRow) Validate() error

type SongsRowIterator

type SongsRowIterator interface {
	Next() (*SongsRow, error)
	Do(f func(row *SongsRow) error) error
	Stop()
}

type SongsTableDescriptor

type SongsTableDescriptor interface {
	TableName() string
	TableID() spansql.ID
	ColumnNames() []string
	ColumnIDs() []spansql.ID
	ColumnExprs() []spansql.Expr
	SingerId() ColumnDescriptor
	AlbumId() ColumnDescriptor
	TrackId() ColumnDescriptor
	SongName() ColumnDescriptor
}

type SpannerReadTransaction

type SpannerReadTransaction interface {
	Read(ctx context.Context, table string, keys spanner.KeySet, columns []string) *spanner.RowIterator
	ReadRow(ctx context.Context, table string, key spanner.Key, columns []string) (*spanner.Row, error)
	Query(ctx context.Context, statement spanner.Statement) *spanner.RowIterator
}

Jump to

Keyboard shortcuts

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