bigtable

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// DefaultProjectID is the default project ID for the BigTable container.
	DefaultProjectID = "test-project"
)

Variables

View Source
var WithProjectID = shared.WithProjectID

WithProjectID re-exports the common GCloud WithProjectID option

Functions

This section is empty.

Types

type Container

type Container struct {
	testcontainers.Container
	// contains filtered or unexported fields
}

Container represents the BigTable container type used in the module

func Run

Run creates an instance of the BigTable GCloud container type. The URI uses the empty string as the protocol.

Example
// runBigTableContainer {
ctx := context.Background()

bigTableContainer, err := tcbigtable.Run(
	ctx,
	"gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators",
	tcbigtable.WithProjectID("bigtable-project"),
)
defer func() {
	if err := testcontainers.TerminateContainer(bigTableContainer); err != nil {
		log.Printf("failed to terminate container: %s", err)
	}
}()
if err != nil {
	log.Printf("failed to run container: %v", err)
	return
}
// }

// bigTableAdminClient {
projectID := bigTableContainer.ProjectID()

const (
	instanceID = "test-instance"
	tableName  = "test-table"
)

options := []option.ClientOption{
	option.WithEndpoint(bigTableContainer.URI()),
	option.WithoutAuthentication(),
	option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
}
adminClient, err := bigtable.NewAdminClient(ctx, projectID, instanceID, options...)
if err != nil {
	log.Printf("failed to create admin client: %v", err)
	return
}
defer adminClient.Close()
// }

err = adminClient.CreateTable(ctx, tableName)
if err != nil {
	log.Printf("failed to create table: %v", err)
	return
}
err = adminClient.CreateColumnFamily(ctx, tableName, "name")
if err != nil {
	log.Printf("failed to create column family: %v", err)
	return
}

// bigTableClient {
client, err := bigtable.NewClient(ctx, projectID, instanceID, options...)
if err != nil {
	log.Printf("failed to create client: %v", err)
	return
}
defer client.Close()
// }

tbl := client.Open(tableName)

mut := bigtable.NewMutation()
mut.Set("name", "firstName", bigtable.Now(), []byte("Gopher"))
err = tbl.Apply(ctx, "1", mut)
if err != nil {
	log.Printf("failed to apply mutation: %v", err)
	return
}

row, err := tbl.ReadRow(ctx, "1", bigtable.RowFilter(bigtable.FamilyFilter("name")))
if err != nil {
	log.Printf("failed to read row: %v", err)
	return
}

fmt.Println(string(row["name"][0].Value))
Output:

Gopher

func (*Container) ProjectID

func (c *Container) ProjectID() string

ProjectID returns the project ID of the BigTable container.

func (*Container) URI

func (c *Container) URI() string

URI returns the URI of the BigTable container.

type Option

type Option = shared.Option

Option aliases the common GCloud option type

Jump to

Keyboard shortcuts

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