clouddatastore

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 11 Imported by: 0

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

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/v2"
	"go.mercari.io/datastore/v2/clouddatastore"
	"go.mercari.io/datastore/v2/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