clouddatastore

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2018 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 FromContext

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

FromContext make new Client by specified context.

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