go: cloud.google.com/go/firestore/apiv1 Index | Examples | Files | Directories

package firestore

import "cloud.google.com/go/firestore/apiv1"

Package firestore is an auto-generated package for the Cloud Firestore API.

Accesses the NoSQL document database built for automatic scaling, high performance, and ease of application development.

Use of Context

The ctx passed to NewClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.

To close the open connection, use the Close() method.

For information about setting deadlines, reusing contexts, and more please visit godoc.org/cloud.google.com/go.

Index

Examples

Package Files

doc.go firestore_client.go info.go

func DefaultAuthScopes Uses

func DefaultAuthScopes() []string

DefaultAuthScopes reports the default set of authentication scopes to use with this package.

type CallOptions Uses

type CallOptions struct {
    GetDocument       []gax.CallOption
    ListDocuments     []gax.CallOption
    UpdateDocument    []gax.CallOption
    DeleteDocument    []gax.CallOption
    BatchGetDocuments []gax.CallOption
    BeginTransaction  []gax.CallOption
    Commit            []gax.CallOption
    Rollback          []gax.CallOption
    RunQuery          []gax.CallOption
    PartitionQuery    []gax.CallOption
    Write             []gax.CallOption
    Listen            []gax.CallOption
    ListCollectionIds []gax.CallOption
    BatchWrite        []gax.CallOption
    CreateDocument    []gax.CallOption
}

CallOptions contains the retry settings for each method of Client.

type Client Uses

type Client struct {

    // The call options for this service.
    CallOptions *CallOptions
    // contains filtered or unexported fields
}

Client is a client for interacting with Cloud Firestore API.

Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

func NewClient Uses

func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)

NewClient creates a new firestore client.

The Cloud Firestore service.

Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL document database that simplifies storing, syncing, and querying data for your mobile, web, and IoT apps at global scale. Its client libraries provide live synchronization and offline support, while its security features and integrations with Firebase and Google Cloud Platform (GCP) accelerate building truly serverless apps.

Code:

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}
// TODO: Use client.
_ = c

func (*Client) BatchGetDocuments Uses

func (c *Client) BatchGetDocuments(ctx context.Context, req *firestorepb.BatchGetDocumentsRequest, opts ...gax.CallOption) (firestorepb.Firestore_BatchGetDocumentsClient, error)

BatchGetDocuments gets multiple documents.

Documents returned by this method are not guaranteed to be returned in the same order that they were requested.

func (*Client) BatchWrite Uses

func (c *Client) BatchWrite(ctx context.Context, req *firestorepb.BatchWriteRequest, opts ...gax.CallOption) (*firestorepb.BatchWriteResponse, error)

BatchWrite applies a batch of write operations.

The BatchWrite method does not apply the write operations atomically and can apply them out of order. Method does not allow more than one write per document. Each write succeeds or fails independently. See the BatchWriteResponse for the success status of each write.

If you require an atomically applied set of writes, use Commit instead.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.BatchWriteRequest{
    // TODO: Fill request struct fields.
}
resp, err := c.BatchWrite(ctx, req)
if err != nil {
    // TODO: Handle error.
}
// TODO: Use resp.
_ = resp

func (*Client) BeginTransaction Uses

func (c *Client) BeginTransaction(ctx context.Context, req *firestorepb.BeginTransactionRequest, opts ...gax.CallOption) (*firestorepb.BeginTransactionResponse, error)

BeginTransaction starts a new transaction.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.BeginTransactionRequest{
    // TODO: Fill request struct fields.
}
resp, err := c.BeginTransaction(ctx, req)
if err != nil {
    // TODO: Handle error.
}
// TODO: Use resp.
_ = resp

func (*Client) Close Uses

func (c *Client) Close() error

Close closes the connection to the API service. The user should invoke this when the client is no longer required.

func (*Client) Commit Uses

func (c *Client) Commit(ctx context.Context, req *firestorepb.CommitRequest, opts ...gax.CallOption) (*firestorepb.CommitResponse, error)

Commit commits a transaction, while optionally updating documents.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.CommitRequest{
    // TODO: Fill request struct fields.
}
resp, err := c.Commit(ctx, req)
if err != nil {
    // TODO: Handle error.
}
// TODO: Use resp.
_ = resp

func (*Client) Connection Uses

func (c *Client) Connection() *grpc.ClientConn

Connection returns a connection to the API service.

Deprecated.

func (*Client) CreateDocument Uses

func (c *Client) CreateDocument(ctx context.Context, req *firestorepb.CreateDocumentRequest, opts ...gax.CallOption) (*firestorepb.Document, error)

CreateDocument creates a new document.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.CreateDocumentRequest{
    // TODO: Fill request struct fields.
}
resp, err := c.CreateDocument(ctx, req)
if err != nil {
    // TODO: Handle error.
}
// TODO: Use resp.
_ = resp

func (*Client) DeleteDocument Uses

func (c *Client) DeleteDocument(ctx context.Context, req *firestorepb.DeleteDocumentRequest, opts ...gax.CallOption) error

DeleteDocument deletes a document.

Code:

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.DeleteDocumentRequest{
    // TODO: Fill request struct fields.
}
err = c.DeleteDocument(ctx, req)
if err != nil {
    // TODO: Handle error.
}

func (*Client) GetDocument Uses

func (c *Client) GetDocument(ctx context.Context, req *firestorepb.GetDocumentRequest, opts ...gax.CallOption) (*firestorepb.Document, error)

GetDocument gets a single document.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.GetDocumentRequest{
    // TODO: Fill request struct fields.
}
resp, err := c.GetDocument(ctx, req)
if err != nil {
    // TODO: Handle error.
}
// TODO: Use resp.
_ = resp

func (*Client) ListCollectionIds Uses

func (c *Client) ListCollectionIds(ctx context.Context, req *firestorepb.ListCollectionIdsRequest, opts ...gax.CallOption) *StringIterator

ListCollectionIds lists all the collection IDs underneath a document.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"
// import "google.golang.org/api/iterator"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.ListCollectionIdsRequest{
    // TODO: Fill request struct fields.
}
it := c.ListCollectionIds(ctx, req)
for {
    resp, err := it.Next()
    if err == iterator.Done {
        break
    }
    if err != nil {
        // TODO: Handle error.
    }
    // TODO: Use resp.
    _ = resp
}

func (*Client) ListDocuments Uses

func (c *Client) ListDocuments(ctx context.Context, req *firestorepb.ListDocumentsRequest, opts ...gax.CallOption) *DocumentIterator

ListDocuments lists documents.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"
// import "google.golang.org/api/iterator"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.ListDocumentsRequest{
    // TODO: Fill request struct fields.
}
it := c.ListDocuments(ctx, req)
for {
    resp, err := it.Next()
    if err == iterator.Done {
        break
    }
    if err != nil {
        // TODO: Handle error.
    }
    // TODO: Use resp.
    _ = resp
}

func (*Client) Listen Uses

func (c *Client) Listen(ctx context.Context, opts ...gax.CallOption) (firestorepb.Firestore_ListenClient, error)

Listen listens to changes.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}
stream, err := c.Listen(ctx)
if err != nil {
    // TODO: Handle error.
}
go func() {
    reqs := []*firestorepb.ListenRequest{
        // TODO: Create requests.
    }
    for _, req := range reqs {
        if err := stream.Send(req); err != nil {
            // TODO: Handle error.
        }
    }
    stream.CloseSend()
}()
for {
    resp, err := stream.Recv()
    if err == io.EOF {
        break
    }
    if err != nil {
        // TODO: handle error.
    }
    // TODO: Use resp.
    _ = resp
}

func (*Client) PartitionQuery Uses

func (c *Client) PartitionQuery(ctx context.Context, req *firestorepb.PartitionQueryRequest, opts ...gax.CallOption) *CursorIterator

PartitionQuery partitions a query by returning partition cursors that can be used to run the query in parallel. The returned partition cursors are split points that can be used by RunQuery as starting/end points for the query results.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"
// import "google.golang.org/api/iterator"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.PartitionQueryRequest{
    // TODO: Fill request struct fields.
}
it := c.PartitionQuery(ctx, req)
for {
    resp, err := it.Next()
    if err == iterator.Done {
        break
    }
    if err != nil {
        // TODO: Handle error.
    }
    // TODO: Use resp.
    _ = resp
}

func (*Client) Rollback Uses

func (c *Client) Rollback(ctx context.Context, req *firestorepb.RollbackRequest, opts ...gax.CallOption) error

Rollback rolls back a transaction.

Code:

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.RollbackRequest{
    // TODO: Fill request struct fields.
}
err = c.Rollback(ctx, req)
if err != nil {
    // TODO: Handle error.
}

func (*Client) RunQuery Uses

func (c *Client) RunQuery(ctx context.Context, req *firestorepb.RunQueryRequest, opts ...gax.CallOption) (firestorepb.Firestore_RunQueryClient, error)

RunQuery runs a query.

func (*Client) SetGoogleClientInfo Uses

func (c *Client) SetGoogleClientInfo(keyval ...string)

SetGoogleClientInfo sets the name and version of the application in the `x-goog-api-client` header passed on each request. Also passes any provided key-value pairs. Intended for use by Google-written clients.

Internal use only.

func (*Client) UpdateDocument Uses

func (c *Client) UpdateDocument(ctx context.Context, req *firestorepb.UpdateDocumentRequest, opts ...gax.CallOption) (*firestorepb.Document, error)

UpdateDocument updates or inserts a document.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}

req := &firestorepb.UpdateDocumentRequest{
    // TODO: Fill request struct fields.
}
resp, err := c.UpdateDocument(ctx, req)
if err != nil {
    // TODO: Handle error.
}
// TODO: Use resp.
_ = resp

func (*Client) Write Uses

func (c *Client) Write(ctx context.Context, opts ...gax.CallOption) (firestorepb.Firestore_WriteClient, error)

Write streams batches of document updates and deletes, in order.

Code:

// import firestorepb "google.golang.org/genproto/googleapis/firestore/v1"

ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
    // TODO: Handle error.
}
stream, err := c.Write(ctx)
if err != nil {
    // TODO: Handle error.
}
go func() {
    reqs := []*firestorepb.WriteRequest{
        // TODO: Create requests.
    }
    for _, req := range reqs {
        if err := stream.Send(req); err != nil {
            // TODO: Handle error.
        }
    }
    stream.CloseSend()
}()
for {
    resp, err := stream.Recv()
    if err == io.EOF {
        break
    }
    if err != nil {
        // TODO: handle error.
    }
    // TODO: Use resp.
    _ = resp
}

type CursorIterator Uses

type CursorIterator struct {

    // Response is the raw response for the current page.
    // It must be cast to the RPC response type.
    // Calling Next() or InternalFetch() updates this value.
    Response interface{}

    // InternalFetch is for use by the Google Cloud Libraries only.
    // It is not part of the stable interface of this package.
    //
    // InternalFetch returns results from a single call to the underlying RPC.
    // The number of results is no greater than pageSize.
    // If there are no more results, nextPageToken is empty and err is nil.
    InternalFetch func(pageSize int, pageToken string) (results []*firestorepb.Cursor, nextPageToken string, err error)
    // contains filtered or unexported fields
}

CursorIterator manages a stream of *firestorepb.Cursor.

func (*CursorIterator) Next Uses

func (it *CursorIterator) Next() (*firestorepb.Cursor, error)

Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.

func (*CursorIterator) PageInfo Uses

func (it *CursorIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

type DocumentIterator Uses

type DocumentIterator struct {

    // Response is the raw response for the current page.
    // It must be cast to the RPC response type.
    // Calling Next() or InternalFetch() updates this value.
    Response interface{}

    // InternalFetch is for use by the Google Cloud Libraries only.
    // It is not part of the stable interface of this package.
    //
    // InternalFetch returns results from a single call to the underlying RPC.
    // The number of results is no greater than pageSize.
    // If there are no more results, nextPageToken is empty and err is nil.
    InternalFetch func(pageSize int, pageToken string) (results []*firestorepb.Document, nextPageToken string, err error)
    // contains filtered or unexported fields
}

DocumentIterator manages a stream of *firestorepb.Document.

func (*DocumentIterator) Next Uses

func (it *DocumentIterator) Next() (*firestorepb.Document, error)

Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.

func (*DocumentIterator) PageInfo Uses

func (it *DocumentIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

type StringIterator Uses

type StringIterator struct {

    // Response is the raw response for the current page.
    // It must be cast to the RPC response type.
    // Calling Next() or InternalFetch() updates this value.
    Response interface{}

    // InternalFetch is for use by the Google Cloud Libraries only.
    // It is not part of the stable interface of this package.
    //
    // InternalFetch returns results from a single call to the underlying RPC.
    // The number of results is no greater than pageSize.
    // If there are no more results, nextPageToken is empty and err is nil.
    InternalFetch func(pageSize int, pageToken string) (results []string, nextPageToken string, err error)
    // contains filtered or unexported fields
}

StringIterator manages a stream of string.

func (*StringIterator) Next Uses

func (it *StringIterator) Next() (string, error)

Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.

func (*StringIterator) PageInfo Uses

func (it *StringIterator) PageInfo() *iterator.PageInfo

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

Directories

PathSynopsis
adminPackage apiv1 is an auto-generated package for the Google Cloud Firestore Admin API.

Package firestore imports 17 packages (graph) and is imported by 7 packages. Updated 2020-07-02. Refresh now. Tools for package owners.