musicdb

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Example (ReadOnlyTransaction_MultipleTables)
package main

import (
	"context"

	"cloud.google.com/go/spanner"
	"go.einride.tech/aip-spanner/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.Singers(tx).Get(ctx, musicdb.SingersKey{
		SingerId: 42,
	})
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	album, err := musicdb.Albums(tx).Get(ctx, musicdb.AlbumsKey{
		SingerId: 42,
		AlbumId:  24,
	})
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	_ = singer // TODO: Use singer.
	_ = album  // TODO: Use album.
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlbumsAndSongsReadTransaction

type AlbumsAndSongsReadTransaction struct {
	Tx SpannerReadTransaction
}

func AlbumsAndSongs

func (AlbumsAndSongsReadTransaction) BatchGet

func (AlbumsAndSongsReadTransaction) Get

func (AlbumsAndSongsReadTransaction) List

type AlbumsAndSongsRow

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

func (AlbumsAndSongsRow) AlbumsRow

func (r AlbumsAndSongsRow) AlbumsRow() *AlbumsRow

func (AlbumsAndSongsRow) Insert

func (r AlbumsAndSongsRow) Insert() []*spanner.Mutation

func (*AlbumsAndSongsRow) Key

func (r *AlbumsAndSongsRow) Key() AlbumsKey

func (*AlbumsAndSongsRow) UnmarshalSpannerRow

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

func (AlbumsAndSongsRow) Update

func (r AlbumsAndSongsRow) Update() []*spanner.Mutation

type AlbumsAndSongsRowIterator

type AlbumsAndSongsRowIterator struct {
	*spanner.RowIterator
}

func (*AlbumsAndSongsRowIterator) Do

func (*AlbumsAndSongsRowIterator) Next

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) QualifiedBoolExpr

func (k AlbumsKey) QualifiedBoolExpr(prefix spansql.PathExp) spansql.BoolExpr

func (AlbumsKey) SpannerKey

func (k AlbumsKey) SpannerKey() spanner.Key

func (AlbumsKey) SpannerKeySet

func (k AlbumsKey) SpannerKeySet() spanner.KeySet

type AlbumsReadTransaction

type AlbumsReadTransaction struct {
	Tx SpannerReadTransaction
}

func Albums

func (AlbumsReadTransaction) BatchGet

func (t AlbumsReadTransaction) BatchGet(
	ctx context.Context,
	keys []AlbumsKey,
) (map[AlbumsKey]*AlbumsRow, error)

func (AlbumsReadTransaction) Get

Example
package main

import (
	"context"

	"cloud.google.com/go/spanner"
	"go.einride.tech/aip-spanner/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.Singers(client.Single()).Get(ctx, musicdb.SingersKey{
		SingerId: 42,
	})
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	_ = singer // TODO: Use singer.
}
Output:

func (AlbumsReadTransaction) List

Example
package main

import (
	"context"

	"cloud.google.com/go/spanner"
	"cloud.google.com/go/spanner/spansql"
	"go.einride.tech/aip-spanner/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.Singers(client.Single()).List(ctx, musicdb.ListQuery{
		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 (AlbumsReadTransaction) Read

type AlbumsRow

type AlbumsRow struct {
	SingerId   int64              `spanner:"SingerId"`
	AlbumId    int64              `spanner:"AlbumId"`
	AlbumTitle spanner.NullString `spanner:"AlbumTitle"`
}

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) Insert

func (r *AlbumsRow) Insert() *spanner.Mutation

func (*AlbumsRow) InsertColumns

func (r *AlbumsRow) InsertColumns(columns []string) *spanner.Mutation

func (*AlbumsRow) InsertOrUpdate

func (r *AlbumsRow) InsertOrUpdate() *spanner.Mutation

func (*AlbumsRow) InsertOrUpdateColumns

func (r *AlbumsRow) InsertOrUpdateColumns(columns []string) *spanner.Mutation

func (*AlbumsRow) Key

func (r *AlbumsRow) Key() AlbumsKey

func (*AlbumsRow) Mutation

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

func (*AlbumsRow) MutationForColumns

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

func (*AlbumsRow) UnmarshalSpannerRow

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

func (*AlbumsRow) Update

func (r *AlbumsRow) Update() *spanner.Mutation

func (*AlbumsRow) UpdateColumns

func (r *AlbumsRow) UpdateColumns(columns []string) *spanner.Mutation

func (*AlbumsRow) Validate

func (r *AlbumsRow) Validate() error

type AlbumsRowIterator

type AlbumsRowIterator struct {
	*spanner.RowIterator
}

func (*AlbumsRowIterator) Do

func (i *AlbumsRowIterator) Do(f func(row *AlbumsRow) error) error

func (*AlbumsRowIterator) Next

func (i *AlbumsRowIterator) Next() (*AlbumsRow, error)

type AlbumsTableDescriptor

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

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 ListQuery

type ListQuery struct {
	Where  spansql.BoolExpr
	Order  []spansql.Order
	Limit  int32
	Offset int64
}

type SingersAndAlbumsReadTransaction

type SingersAndAlbumsReadTransaction struct {
	Tx SpannerReadTransaction
}

func SingersAndAlbums

func (SingersAndAlbumsReadTransaction) BatchGet

func (SingersAndAlbumsReadTransaction) Get

func (SingersAndAlbumsReadTransaction) List

type SingersAndAlbumsRow

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

func (SingersAndAlbumsRow) Insert

func (r SingersAndAlbumsRow) Insert() []*spanner.Mutation

func (*SingersAndAlbumsRow) Key

func (SingersAndAlbumsRow) SingersRow

func (r SingersAndAlbumsRow) SingersRow() *SingersRow

func (*SingersAndAlbumsRow) UnmarshalSpannerRow

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

func (SingersAndAlbumsRow) Update

func (r SingersAndAlbumsRow) Update() []*spanner.Mutation

type SingersAndAlbumsRowIterator

type SingersAndAlbumsRowIterator struct {
	*spanner.RowIterator
}

func (*SingersAndAlbumsRowIterator) Do

func (*SingersAndAlbumsRowIterator) Next

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) QualifiedBoolExpr

func (k SingersKey) QualifiedBoolExpr(prefix spansql.PathExp) spansql.BoolExpr

func (SingersKey) SpannerKey

func (k SingersKey) SpannerKey() spanner.Key

func (SingersKey) SpannerKeySet

func (k SingersKey) SpannerKeySet() spanner.KeySet

type SingersReadTransaction

type SingersReadTransaction struct {
	Tx SpannerReadTransaction
}

func Singers

func (SingersReadTransaction) BatchGet

func (t SingersReadTransaction) BatchGet(
	ctx context.Context,
	keys []SingersKey,
) (map[SingersKey]*SingersRow, error)

func (SingersReadTransaction) Get

func (SingersReadTransaction) List

func (SingersReadTransaction) Read

type SingersRow

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

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) Insert

func (r *SingersRow) Insert() *spanner.Mutation

func (*SingersRow) InsertColumns

func (r *SingersRow) InsertColumns(columns []string) *spanner.Mutation

func (*SingersRow) InsertOrUpdate

func (r *SingersRow) InsertOrUpdate() *spanner.Mutation

func (*SingersRow) InsertOrUpdateColumns

func (r *SingersRow) InsertOrUpdateColumns(columns []string) *spanner.Mutation

func (*SingersRow) Key

func (r *SingersRow) Key() SingersKey

func (*SingersRow) Mutation

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

func (*SingersRow) MutationForColumns

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

func (*SingersRow) UnmarshalSpannerRow

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

func (*SingersRow) Update

func (r *SingersRow) Update() *spanner.Mutation

func (*SingersRow) UpdateColumns

func (r *SingersRow) UpdateColumns(columns []string) *spanner.Mutation

func (*SingersRow) Validate

func (r *SingersRow) Validate() error

type SingersRowIterator

type SingersRowIterator struct {
	*spanner.RowIterator
}

func (*SingersRowIterator) Do

func (i *SingersRowIterator) Do(f func(row *SingersRow) error) error

func (*SingersRowIterator) Next

func (i *SingersRowIterator) Next() (*SingersRow, error)

type SingersTableDescriptor

type SingersTableDescriptor interface {
	TableName() string
	TableID() spansql.ID
	ColumnNames() []string
	ColumnIDs() []spansql.ID
	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) QualifiedBoolExpr

func (k SongsKey) QualifiedBoolExpr(prefix spansql.PathExp) spansql.BoolExpr

func (SongsKey) SpannerKey

func (k SongsKey) SpannerKey() spanner.Key

func (SongsKey) SpannerKeySet

func (k SongsKey) SpannerKeySet() spanner.KeySet

type SongsReadTransaction

type SongsReadTransaction struct {
	Tx SpannerReadTransaction
}

func Songs

func (SongsReadTransaction) BatchGet

func (t SongsReadTransaction) BatchGet(
	ctx context.Context,
	keys []SongsKey,
) (map[SongsKey]*SongsRow, error)

func (SongsReadTransaction) Get

func (t SongsReadTransaction) Get(
	ctx context.Context,
	key SongsKey,
) (*SongsRow, error)

func (SongsReadTransaction) List

func (SongsReadTransaction) Read

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) Insert

func (r *SongsRow) Insert() *spanner.Mutation

func (*SongsRow) InsertColumns

func (r *SongsRow) InsertColumns(columns []string) *spanner.Mutation

func (*SongsRow) InsertOrUpdate

func (r *SongsRow) InsertOrUpdate() *spanner.Mutation

func (*SongsRow) InsertOrUpdateColumns

func (r *SongsRow) InsertOrUpdateColumns(columns []string) *spanner.Mutation

func (*SongsRow) Key

func (r *SongsRow) Key() SongsKey

func (*SongsRow) Mutation

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

func (*SongsRow) MutationForColumns

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

func (*SongsRow) UnmarshalSpannerRow

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

func (*SongsRow) Update

func (r *SongsRow) Update() *spanner.Mutation

func (*SongsRow) UpdateColumns

func (r *SongsRow) UpdateColumns(columns []string) *spanner.Mutation

func (*SongsRow) Validate

func (r *SongsRow) Validate() error

type SongsRowIterator

type SongsRowIterator struct {
	*spanner.RowIterator
}

func (*SongsRowIterator) Do

func (i *SongsRowIterator) Do(f func(row *SongsRow) error) error

func (*SongsRowIterator) Next

func (i *SongsRowIterator) Next() (*SongsRow, error)

type SongsTableDescriptor

type SongsTableDescriptor interface {
	TableName() string
	TableID() spansql.ID
	ColumnNames() []string
	ColumnIDs() []spansql.ID
	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