musicdb

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 7 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 BatchGetLabelsRowsQuery added in v0.49.2

type BatchGetLabelsRowsQuery struct {
	Keys []LabelsKey
}

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 {
	Labels() LabelsTableDescriptor
	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 GetLabelsRowQuery added in v0.49.2

type GetLabelsRowQuery struct {
	Key LabelsKey
}

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 LabelsKey added in v0.49.2

type LabelsKey struct {
	LabelId int64
}

func (LabelsKey) BoolExpr added in v0.49.2

func (k LabelsKey) BoolExpr() spansql.BoolExpr

func (LabelsKey) Delete added in v0.49.2

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

func (LabelsKey) Order added in v0.49.2

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

func (LabelsKey) SpannerKey added in v0.49.2

func (k LabelsKey) SpannerKey() spanner.Key

func (LabelsKey) SpannerKeySet added in v0.49.2

func (k LabelsKey) SpannerKeySet() spanner.KeySet

type LabelsRow added in v0.49.2

type LabelsRow struct {
	LabelId   int64              `spanner:"LabelId"`
	LabelName spanner.NullString `spanner:"LabelName"`
}

func (*LabelsRow) ColumnExprs added in v0.49.2

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

func (*LabelsRow) ColumnIDs added in v0.49.2

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

func (*LabelsRow) ColumnNames added in v0.49.2

func (*LabelsRow) ColumnNames() []string

func (*LabelsRow) Key added in v0.49.2

func (r *LabelsRow) Key() LabelsKey

func (*LabelsRow) Mutate added in v0.49.2

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

func (*LabelsRow) MutateColumns added in v0.49.2

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

func (*LabelsRow) MutatePresentColumns added in v0.49.2

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

func (*LabelsRow) UnmarshalSpannerRow added in v0.49.2

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

func (*LabelsRow) Validate added in v0.49.2

func (r *LabelsRow) Validate() error

type LabelsRowIterator added in v0.49.2

type LabelsRowIterator interface {
	Next() (*LabelsRow, error)
	Do(f func(row *LabelsRow) error) error
	Stop()
}

type LabelsTableDescriptor added in v0.49.2

type LabelsTableDescriptor interface {
	TableName() string
	TableID() spansql.ID
	ColumnNames() []string
	ColumnIDs() []spansql.ID
	ColumnExprs() []spansql.Expr
	LabelId() ColumnDescriptor
	LabelName() ColumnDescriptor
}

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 ListLabelsRowsQuery added in v0.49.2

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

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) BatchGetLabelsRows added in v0.49.2

func (t ReadTransaction) BatchGetLabelsRows(
	ctx context.Context,
	query BatchGetLabelsRowsQuery,
) (map[LabelsKey]*LabelsRow, 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) GetLabelsRow added in v0.49.2

func (t ReadTransaction) GetLabelsRow(
	ctx context.Context,
	query GetLabelsRowQuery,
) (*LabelsRow, 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) ListLabelsRows added in v0.49.2

func (t ReadTransaction) ListLabelsRows(
	ctx context.Context,
	query ListLabelsRowsQuery,
) LabelsRowIterator

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) ReadLabelsRows added in v0.49.2

func (t ReadTransaction) ReadLabelsRows(
	ctx context.Context,
	keySet spanner.KeySet,
) LabelsRowIterator

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"`
	LabelId    spanner.NullInt64  `spanner:"LabelId"`
	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
	LabelId() 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
	ReadUsingIndex(ctx context.Context, table, index string, keys spanner.KeySet, columns []string) *spanner.RowIterator
	ReadRow(ctx context.Context, table string, key spanner.Key, columns []string) (*spanner.Row, error)
	ReadRowUsingIndex(ctx context.Context, table string, index 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