clouddatastore

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MIT Imports: 9 Imported by: 18

Documentation

Overview

Package clouddatastore provides Cloud Datastore implementation of datastore.Client. This package wrapping cloud.google.com/go/datastore package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromClient added in v1.3.0

func FromClient(ctx context.Context, client *datastore.Client) (w.Client, error)

FromClient make new Client by specified datastore.Client.

func FromContext

func FromContext(ctx context.Context, opts ...w.ClientOption) (w.Client, error)

FromContext make new Client by specified context. Deprecated: use FromClient instead of FromContext. FromContext implicitly creates original datastore.Client.

Example
package main

import (
	"context"
	"fmt"

	"go.mercari.io/datastore"
	"go.mercari.io/datastore/clouddatastore"
	"go.mercari.io/datastore/internal/testutils"
)

const ProjectID = "datastore-wrapper"

func main() {
	ctx := context.Background()
	client, err := clouddatastore.FromContext(
		ctx,
		datastore.WithProjectID(ProjectID),
	)
	if err != nil {
		panic(err)
	}
	defer client.Close()
	defer testutils.CleanUpAllEntities(ctx, client)

	type Data struct {
		Name string
	}

	key := client.IncompleteKey("Data", nil)
	entity := &Data{Name: "mercari"}
	key, err = client.Put(ctx, key, entity)
	if err != nil {
		panic(err)
	}

	entity = &Data{}
	err = client.Get(ctx, key, entity)
	if err != nil {
		panic(err)
	}

	fmt.Println(entity.Name)
}
Output:

mercari

func IsCloudDatastoreClient

func IsCloudDatastoreClient(client w.Client) bool

IsCloudDatastoreClient returns check result that client is this package's client or not.

Types

This section is empty.

Jump to

Keyboard shortcuts

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