datastore: go.mercari.io/datastore/clouddatastore Index | Examples | Files

package clouddatastore

import "go.mercari.io/datastore/clouddatastore"

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

Index

Examples

Package Files

bridge.go client.go convert.go doc.go key.go query.go transaction.go

func FromClient Uses

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

FromClient make new Client by specified datastore.Client.

func FromContext Uses

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

FromContext make new Client by specified context.

Code:

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)
}

func IsCloudDatastoreClient Uses

func IsCloudDatastoreClient(client w.Client) bool

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

Package clouddatastore imports 9 packages (graph) and is imported by 2 packages. Updated 2018-11-05. Refresh now. Tools for package owners.