spannerr

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2018 License: MIT Imports: 10 Imported by: 0

README

GoDoc

Spanner R is a convenience wrapper for Google Cloud Spanner's REST client

Cloud Spanner' REST API docs

The main purpose of this client is to add a layer of session management. More inforomation on Spanner sessions can be found here: https://cloud.google.com/spanner/docs/sessions

If you are not on running your services on App Engine, you should just use the official Spanner (gRPC) client

Documentation

Overview

Package spannerr (pronounced Spanner R, or Spanner-er) provides session management and a simple interface for Google Cloud Spanner's REST API. If you are not on running your services on Google App Engine, you should just use the official Cloud Spanner (gRPC) client: https://godoc.org/cloud.google.com/go/spanner

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client allows users to manage sessions on Google Cloud Spanner.

func NewClient

func NewClient(project, instances, database string, maxSessions int) *Client

NewClient returns a new Client implementation.

func (*Client) AcquireSession

func (c *Client) AcquireSession(ctx context.Context) (*Session, error)

AcquireSession will pull an existing session from the local cache. If the session cache is not full, it will create a new session and put it in the cache. Users must pass the Session to ReleaseSession when work is complete.

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close will attempt to end all existing sessions. If you have shutdown hooks available for your instance type, call this then. If you do not have shutdown hooks, the sessions made will be closed automatically after one hour of idle time: https://cloud.google.com/spanner/docs/sessions

func (*Client) ReleaseSession

func (c *Client) ReleaseSession(ctx context.Context, sess Session)

ReleaseSession will make the session available in the cache again. Call this after first acquiring a session.

type Param

type Param struct {
	// Name is the name of the parameter used within the sql.
	Name string
	// Value is the value of the parameter to pass into the query.
	Value interface{}
	// Type will be used to populate the spanner.Type.Code field. More details
	// can be found here: https://godoc.org/google.golang.org/api/spanner/v1#Type
	Type string
	// ArrayElementType will be used to populate the spanner.Type.Code field of a
	// nested array type. More details can be found here:
	// https://godoc.org/google.golang.org/api/spanner/v1#Type
	ArrayElementType string
}

Param contains the information required to pass a parameter to a Cloud Spanner query.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session represents a live session on Google Cloud Spanner.

func (*Session) BeginTransaction added in v0.2.0

func (s *Session) BeginTransaction(ctx context.Context, opts *spanner.BeginTransactionRequest) (*spanner.Transaction, error)

BeginTransaction starts a new transaction.

func (*Session) Commit

func (s *Session) Commit(ctx context.Context, mutations []*spanner.Mutation, opts *spanner.TransactionOptions, txID string) (*spanner.CommitResponse, error)

Commit commits a transaction. The request includes the mutations to be applied to rows in the database. Including opts signals a one-off query, whereas including txID signals this commit is part of a larger transaction. This function wraps https://godoc.org/google.golang.org/api/spanner/v1#ProjectsInstancesDatabasesSessionsService.Commit

func (*Session) ExecuteSQL

func (s *Session) ExecuteSQL(ctx context.Context, params []*Param, sql, queryMode string, tx *spanner.TransactionSelector) (*spanner.ResultSet, error)

ExecuteSQL executes an SQL query, returning all rows in a single reply. It can be called within a transaction by including a TransactionSelector with its Id field set. This function wraps https://godoc.org/google.golang.org/api/spanner/v1#ProjectsInstancesDatabasesSessionsExecuteSqlCall

func (*Session) Rollback added in v0.2.1

func (s *Session) Rollback(ctx context.Context, txID string) error

Rollback rolls back a transaction.

Jump to

Keyboard shortcuts

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