package firestore
import "cloud.google.com/go/firestore/apiv1beta1"
Package firestore is an auto-generated package for the Google Cloud Firestore API.
NOTE: This package is in beta. It is not stable, and may be subject to changes.
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.
Use the client at cloud.google.com/go/firestore in preference to this.
Index ¶
- func DefaultAuthScopes() []string
- type CallOptions
- type Client
- func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)
- func (c *Client) BatchGetDocuments(ctx context.Context, req *firestorepb.BatchGetDocumentsRequest, opts ...gax.CallOption) (firestorepb.Firestore_BatchGetDocumentsClient, error)
- func (c *Client) BeginTransaction(ctx context.Context, req *firestorepb.BeginTransactionRequest, opts ...gax.CallOption) (*firestorepb.BeginTransactionResponse, error)
- func (c *Client) Close() error
- func (c *Client) Commit(ctx context.Context, req *firestorepb.CommitRequest, opts ...gax.CallOption) (*firestorepb.CommitResponse, error)
- func (c *Client) Connection() *grpc.ClientConn
- func (c *Client) CreateDocument(ctx context.Context, req *firestorepb.CreateDocumentRequest, opts ...gax.CallOption) (*firestorepb.Document, error)
- func (c *Client) DeleteDocument(ctx context.Context, req *firestorepb.DeleteDocumentRequest, opts ...gax.CallOption) error
- func (c *Client) GetDocument(ctx context.Context, req *firestorepb.GetDocumentRequest, opts ...gax.CallOption) (*firestorepb.Document, error)
- func (c *Client) ListCollectionIds(ctx context.Context, req *firestorepb.ListCollectionIdsRequest, opts ...gax.CallOption) *StringIterator
- func (c *Client) ListDocuments(ctx context.Context, req *firestorepb.ListDocumentsRequest, opts ...gax.CallOption) *DocumentIterator
- func (c *Client) Listen(ctx context.Context, opts ...gax.CallOption) (firestorepb.Firestore_ListenClient, error)
- func (c *Client) Rollback(ctx context.Context, req *firestorepb.RollbackRequest, opts ...gax.CallOption) error
- func (c *Client) RunQuery(ctx context.Context, req *firestorepb.RunQueryRequest, opts ...gax.CallOption) (firestorepb.Firestore_RunQueryClient, error)
- func (c *Client) SetGoogleClientInfo(keyval ...string)
- func (c *Client) UpdateDocument(ctx context.Context, req *firestorepb.UpdateDocumentRequest, opts ...gax.CallOption) (*firestorepb.Document, error)
- func (c *Client) Write(ctx context.Context, opts ...gax.CallOption) (firestorepb.Firestore_WriteClient, error)
- type DocumentIterator
- func (it *DocumentIterator) Next() (*firestorepb.Document, error)
- func (it *DocumentIterator) PageInfo() *iterator.PageInfo
- type StringIterator
Examples ¶
- Client.BatchGetDocuments
- Client.BeginTransaction
- Client.Commit
- Client.CreateDocument
- Client.DeleteDocument
- Client.GetDocument
- Client.ListCollectionIds
- Client.ListDocuments
- Client.Listen
- Client.Rollback
- Client.RunQuery
- Client.UpdateDocument
- Client.Write
- NewClient
Functions ¶
func DefaultAuthScopes ¶
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
Types ¶
type CallOptions ¶
type CallOptions struct { GetDocument []gax.CallOption ListDocuments []gax.CallOption CreateDocument []gax.CallOption UpdateDocument []gax.CallOption DeleteDocument []gax.CallOption BatchGetDocuments []gax.CallOption BeginTransaction []gax.CallOption Commit []gax.CallOption Rollback []gax.CallOption RunQuery []gax.CallOption Write []gax.CallOption Listen []gax.CallOption ListCollectionIds []gax.CallOption }
CallOptions contains the retry settings for each method of Client.
type Client ¶
type Client struct { // The call options for this service. CallOptions *CallOptions // contains filtered or unexported fields }
Client is a client for interacting with Google Cloud Firestore API.
Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
func NewClient ¶
NewClient creates a new firestore client.
The Cloud Firestore service.
This service exposes several types of comparable timestamps:
create_time - The time at which a document was created. Changes only when a document is deleted, then re-created. Increases in a strict monotonic fashion. update_time - The time at which a document was last updated. Changes every time a document is modified. Does not change when a write results in no modifications. Increases in a strict monotonic fashion. read_time - The time at which a particular state was observed. Used to denote a consistent snapshot of the database or the time at which a Document was observed to not exist. commit_time - The time at which the writes in a transaction were committed. Any read with an equal or greater read_time is guaranteed to see the effects of the transaction.
Example¶
Code:play
package main import ( "context" firestore "cloud.google.com/go/firestore/apiv1beta1" ) func main() { ctx := context.Background() c, err := firestore.NewClient(ctx) if err != nil { // TODO: Handle error. } // TODO: Use client. _ = c }
func (*Client) BatchGetDocuments ¶
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.
Code:play
Example¶
package main
import (
"context"
"io"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &firestorepb.BatchGetDocumentsRequest{
// TODO: Fill request struct fields.
}
stream, err := c.BatchGetDocuments(ctx, req)
if err != nil {
// TODO: Handle error.
}
for {
resp, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
// TODO: handle error.
}
// TODO: Use resp.
_ = resp
}
}
func (*Client) BeginTransaction ¶
func (c *Client) BeginTransaction(ctx context.Context, req *firestorepb.BeginTransactionRequest, opts ...gax.CallOption) (*firestorepb.BeginTransactionResponse, error)
BeginTransaction starts a new transaction.
Code:play
Example¶
package main
import (
"context"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 ¶
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*Client) Commit ¶
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:play
Example¶
package main
import (
"context"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 ¶
func (c *Client) Connection() *grpc.ClientConn
Connection returns the client's connection to the API service.
func (*Client) CreateDocument ¶
func (c *Client) CreateDocument(ctx context.Context, req *firestorepb.CreateDocumentRequest, opts ...gax.CallOption) (*firestorepb.Document, error)
CreateDocument creates a new document.
Code:play
Example¶
package main
import (
"context"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 ¶
func (c *Client) DeleteDocument(ctx context.Context, req *firestorepb.DeleteDocumentRequest, opts ...gax.CallOption) error
DeleteDocument deletes a document.
Code:play
Example¶
package main
import (
"context"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 ¶
func (c *Client) GetDocument(ctx context.Context, req *firestorepb.GetDocumentRequest, opts ...gax.CallOption) (*firestorepb.Document, error)
GetDocument gets a single document.
Code:play
Example¶
package main
import (
"context"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 ¶
func (c *Client) ListCollectionIds(ctx context.Context, req *firestorepb.ListCollectionIdsRequest, opts ...gax.CallOption) *StringIterator
ListCollectionIds lists all the collection IDs underneath a document.
Code:play
Example¶
package main
import (
"context"
firestore "cloud.google.com/go/firestore/apiv1beta1"
"google.golang.org/api/iterator"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 ¶
func (c *Client) ListDocuments(ctx context.Context, req *firestorepb.ListDocumentsRequest, opts ...gax.CallOption) *DocumentIterator
ListDocuments lists documents.
Code:play
Example¶
package main
import (
"context"
firestore "cloud.google.com/go/firestore/apiv1beta1"
"google.golang.org/api/iterator"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 ¶
func (c *Client) Listen(ctx context.Context, opts ...gax.CallOption) (firestorepb.Firestore_ListenClient, error)
Listen listens to changes.
Code:play
Example¶
package main
import (
"context"
"io"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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) Rollback ¶
func (c *Client) Rollback(ctx context.Context, req *firestorepb.RollbackRequest, opts ...gax.CallOption) error
Rollback rolls back a transaction.
Code:play
Example¶
package main
import (
"context"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 ¶
func (c *Client) RunQuery(ctx context.Context, req *firestorepb.RunQueryRequest, opts ...gax.CallOption) (firestorepb.Firestore_RunQueryClient, error)
RunQuery runs a query.
Code:play
Example¶
package main
import (
"context"
"io"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
ctx := context.Background()
c, err := firestore.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &firestorepb.RunQueryRequest{
// TODO: Fill request struct fields.
}
stream, err := c.RunQuery(ctx, req)
if err != nil {
// TODO: Handle error.
}
for {
resp, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
// TODO: handle error.
}
// TODO: Use resp.
_ = resp
}
}
func (*Client) SetGoogleClientInfo ¶
SetGoogleClientInfo sets the name and version of the application in the `x-goog-api-client` header passed on each request. Intended for use by Google-written clients.
func (*Client) UpdateDocument ¶
func (c *Client) UpdateDocument(ctx context.Context, req *firestorepb.UpdateDocumentRequest, opts ...gax.CallOption) (*firestorepb.Document, error)
UpdateDocument updates or inserts a document.
Code:play
Example¶
package main
import (
"context"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 ¶
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:play
Example¶
package main
import (
"context"
"io"
firestore "cloud.google.com/go/firestore/apiv1beta1"
firestorepb "google.golang.org/genproto/googleapis/firestore/v1beta1"
)
func main() {
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 DocumentIterator ¶
type DocumentIterator struct { // 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 ¶
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 ¶
func (it *DocumentIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type StringIterator ¶
type StringIterator struct { // 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 ¶
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 ¶
func (it *StringIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
Source Files ¶
doc.go firestore_client.go
- Version
- v0.46.0
- Published
- Sep 13, 2019
- Platform
- windows/amd64
- Imports
- 17 packages
- Last checked
- 26 minutes ago –
Tools for package owners.