Categorygithub.com/sonatard/datastore
modulepackage
1.3.0
Repository: https://github.com/sonatard/datastore.git
Documentation: pkg.go.dev

# README

Datastore Wrapper Go Documentation CircleCI

(AppEngine | Cloud) Datastore wrapper for Go 👉

Simple. Happy. Respect standard library.

$ go get -u go.mercari.io/datastore

Feature

DO

  • Wrap google.golang.org/appengine/datastore and cloud.google.com/go/datastore
    • keep key behavior
    • align to cloud.google.com/go/datastore first
  • Re-implement datastore package
  • Re-implement datastore.SaveStruct & LoadStruct
    • Ignore unmapped property
    • Add PropertyTranslator interface
      • Convert types like mytime.Unix to time.Time and reverse it
      • Rename property like CreatedAt to createdAt or created_at and reverse it
  • Re-implement PropertyLoadSaver
    • Pass context.Context to Save & Load method
  • Add retry feature to each RPC
    • e.g. Retry AllocateID when it failed
  • Add middleware layer
    • About...
      • Local Cache
      • AE Memcache
      • Logging
      • Retry
      • etc...
    • Easy to ON/OFF switching
  • Add some useful methods
    • aedatastore/TransactionContext

DON'T

  • have utility functions
  • support firestore

Restriction

  • aedatastore package
    • When using slice of struct, MUST specified datastore:",flatten" option.
      • original (ae & cloud) datastore.SaveStruct have different behaviors.
      • see aeprodtest/main.go /api/test3

Committers

Contribution

Please read the CLA below carefully before submitting your contribution.

https://www.mercari.com/cla/

Setup environment & Run tests

  • requirements
    • gcloud sdk
      • gcloud components install app-engine-go
      • gcloud components install beta cloud-datastore-emulator
    • dep
      • go get -u github.com/golang/dep/cmd/dep
  1. Testing in local
$ ./setup.sh # exec once
$ ./serve.sh # exec in background
$ ./test.sh
  1. Testing with Circle CI CLI
$ circleci build

License

Copyright 2017 Mercari, Inc.

Licensed under the MIT License.

# Packages

Package aedatastore provides AppEngine Datastore implementation of datastore.Client.
Package aeprodtest has nothing to use in your application.
Package boom handles the troublesome processing of datastore.Key automatically.
Package clouddatastore provides Cloud Datastore implementation of datastore.Client.
Package dsmiddleware does not have anything, but it has a middleware group as a subpackage.
No description provided by the author
Package testsuite has nothing to use in your application.

# Functions

LoadStruct loads the properties from p to dst.
SaveStruct returns the properties from src as a slice of Properties.
WithCredentialsFile returns a ClientOption that authenticates API calls with the given service account or refresh token JSON credentials file.
WithHTTPClient returns a ClientOption that specifies the HTTP client to use as the basis of communications.
WithProjectID returns a ClientOption that specifies ProjectID to be used in client.
WithScopes returns a ClientOption that overrides the default OAuth2 scopes to be used for a service.
WithTokenSource returns a ClientOption that specifies an OAuth2 token source to be used as the basis for authentication.

# Variables

ErrConcurrentTransaction is returned when a transaction is rolled back due to a conflict with a concurrent transaction.
ErrInvalidEntityType is returned when functions like Get or Next are passed a dst or src argument of invalid type.
ErrInvalidKey is returned when an invalid key is presented.
ErrNoSuchEntity is returned when no entity was found for a given key.
FromContext provides default ClientGenerator.
LoadEntity to dst struct.
SaveEntity convert key & struct to *Entity.
SuppressErrFieldMismatch when this flag is true.

# Structs

Batch can queue operations on Datastore and process them in batch.
An Entity is the value type for a nested struct.
ErrFieldMismatch is returned when a field is to be loaded into a different type than the one it was stored from, or when a field is missing or unexported in the destination struct.
GeoPoint represents a location as latitude/longitude in degrees.
MiddlewareInfo provides RPC's processing state.
Property is a name/value pair plus some metadata.
QueryDump provides information of executed query.
QueryFilterCondition provides information of filter of query.
TransactionBatch provides Batch operation under Transaction.

# Interfaces

Client is a client for reading and writing data in a datastore dataset.
A ClientOption is an option for a Datastore client.
Commit represents the result of a committed transaction.
Cursor is an iterator's position.
Iterator is the result of running a query.
Key represents the datastore key for a stored entity.
KeyLoader can store a Key.
Middleware hooks to the Datastore's RPC and It can modify arguments and return values.
PendingKey represents the key for newly-inserted entity.
PropertyLoadSaver can be converted from and to a slice of Properties.
PropertyTranslator is for converting the value of Property when saving and loading.
Query represents a datastore query.
Transaction represents a set of datastore operations to be committed atomically.

# Type aliases

BatchErrHandler represents Entity's individual callback when batching non-Put processing.
BatchPutHandler represents Entity's individual callback when batching Put processing.
ClientGenerator represents the type of function for generating Client.
MultiError is returned by batch operations when there are errors with particular elements.
PropertyList converts a []Property to implement PropertyLoadSaver.
TxBatchPutHandler represents Entity's individual callback when batching Put with transaction processing.