dsent

package module
v0.0.0-...-6e030ca Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 11 Imported by: 0

README

dsent

Entity helper for GCP Datastore

Usage

See datastore_test.go for example usage.

Documentation

Overview

Package dsent provides a wrapper around the Google Cloud Datastore client to simplify common operations for working with entities in Datastore.

RegisterKind registers a new kind with the given name. It checks if the kind is already registered and panics if it is.

Index

Constants

This section is empty.

Variables

View Source
var ErrConcurrentTransaction = datastore.ErrConcurrentTransaction

ErrConcurrentTransaction is returned when a concurrent transaction is detected.

View Source
var ErrKeyChanged = errors.New("key changed during transaction")

ErrKeyChanged is returned when the key of an entity has changed during a transaction.

ErrNotFound is returned when an entity is not found in Datastore.

View Source
var ErrUpdateAbort = errors.New("update aborted")

ErrUpdateAbort is returned when an update operation is aborted.

Functions

func DecryptMessage

func DecryptMessage(key string, message string) (string, error)

DecryptMessage decrypts a message using AES-256 with a arbitrary key. Use it to decrypt the cursor string.

func EncryptMessage

func EncryptMessage(key string, message string) (string, error)

EncryptMessage encrypts a message using AES-256 with a arbitrary key. Use it to encrypt the cursor string.

func RegisterKind

func RegisterKind(name string)

func SetNS

func SetNS(key *datastore.Key, ns string) *datastore.Key

SetNS is a helper sets the namespace of a Datastore key and its parent keys.

Types

type DSEnt

type DSEnt[T Object] struct {
	*datastore.Client
	// contains filtered or unexported fields
}

DSEnt is a generic Datastore entity wrapper that provides methods for performing common operations on entities.

func NewDSEnt

func NewDSEnt[T Object](client *datastore.Client, ns string, kind string) *DSEnt[T]

NewDSEnt creates a new instance of DSEnt with the given Datastore client and namespace.

func (*DSEnt[T]) BatchCreate

func (db *DSEnt[T]) BatchCreate(ctx context.Context, objs []T) ([]*datastore.Key, []T, error)

BatchCreate creates multiple entities in Datastore within a transaction.

func (*DSEnt[T]) BatchCreateTx

func (db *DSEnt[T]) BatchCreateTx(tx *datastore.Transaction, objs []T) ([]*datastore.PendingKey, []T, error)

BatchCreateTx creates multiple entities in Datastore within a transaction.

func (*DSEnt[T]) BatchDelete

func (db *DSEnt[T]) BatchDelete(ctx context.Context, objs []T) error

BatchDelete is transactional batch delete.

func (*DSEnt[T]) BatchDeleteTx

func (db *DSEnt[T]) BatchDeleteTx(tx *datastore.Transaction, objs []T) error

BatchDeleteTx is used to delete multiple entities in a transaction.

func (*DSEnt[T]) BatchGet

func (db *DSEnt[T]) BatchGet(ctx context.Context, objs []T) ([]T, error)

BatchGet retrieves multiple entities from Datastore.

func (*DSEnt[T]) BatchGetTx

func (db *DSEnt[T]) BatchGetTx(tx *datastore.Transaction, objs []T) ([]T, error)

BatchGetTx retrieves multiple entities from Datastore within a transaction.

func (*DSEnt[T]) BatchPut

func (db *DSEnt[T]) BatchPut(ctx context.Context, objs []T) ([]*datastore.Key, []T, error)

BatchPut saves multiple entities to Datastore within a transaction.

func (*DSEnt[T]) BatchPutTx

func (db *DSEnt[T]) BatchPutTx(tx *datastore.Transaction, objs []T) ([]*datastore.PendingKey, []T, error)

BatchPutTx saves multiple entities to Datastore within a transaction.

func (*DSEnt[T]) Close

func (db *DSEnt[T]) Close()

func (*DSEnt[T]) Create

func (db *DSEnt[T]) Create(ctx context.Context, obj T) (*datastore.Key, T, error)

Create creates a new entity in Datastore.

func (*DSEnt[T]) CreateTx

func (db *DSEnt[T]) CreateTx(tx *datastore.Transaction, obj T) (*datastore.PendingKey, T, error)

CreateTx creates a new entity in Datastore within a transaction.

func (*DSEnt[T]) Delete

func (db *DSEnt[T]) Delete(ctx context.Context, obj T) error

Delete deletes an entity from Datastore.

func (*DSEnt[T]) DeleteTx

func (db *DSEnt[T]) DeleteTx(tx *datastore.Transaction, obj T) error

DeleteTx deletes an entity from Datastore within a transaction.

func (*DSEnt[T]) Exists

func (db *DSEnt[T]) Exists(ctx context.Context, obj T) (bool, error)

Exists checks if an entity exists in Datastore.

func (*DSEnt[T]) ExistsTx

func (db *DSEnt[T]) ExistsTx(ctx context.Context, tx *datastore.Transaction, obj T) (bool, error)

ExistsTx checks if an entity exists in Datastore within a transaction.

func (*DSEnt[T]) Get

func (db *DSEnt[T]) Get(ctx context.Context, obj T) (T, error)

Get retrieves an entity from Datastore and populates the input object with the retrieved data.

func (*DSEnt[T]) GetTx

func (db *DSEnt[T]) GetTx(tx *datastore.Transaction, obj T) (T, error)

GetTx retrieves an entity from Datastore within a transaction and populates the input object with the retrieved data.

func (*DSEnt[T]) Namespace

func (db *DSEnt[T]) Namespace() string

func (*DSEnt[T]) NewQuery

func (db *DSEnt[T]) NewQuery() *datastore.Query

func (*DSEnt[T]) Put

func (db *DSEnt[T]) Put(ctx context.Context, obj T) (*datastore.Key, T, error)

Put saves an entity to Datastore.

func (*DSEnt[T]) PutTx

func (db *DSEnt[T]) PutTx(tx *datastore.Transaction, obj T) (*datastore.PendingKey, T, error)

PutTx saves a single entity to Datastore within a transaction.

func (*DSEnt[T]) ResolveKey

func (db *DSEnt[T]) ResolveKey(key *datastore.Key, obj T) error

ResolveKey resolves the key of an object by calling its LoadKey method.

func (*DSEnt[T]) Update

func (db *DSEnt[T]) Update(
	ctx context.Context, obj T,
	updateFunc func(T) (T, error),
	createFunc func(T) (T, error),
) (T, error)

Update updates an entity in Datastore within a transaction.

func (*DSEnt[T]) UpdateTx

func (db *DSEnt[T]) UpdateTx(
	tx *datastore.Transaction, obj T,
	updateFunc func(T) (T, error),
	createFunc func(T) (T, error),
) (T, error)

UpdateTx updates an entity in Datastore within a transaction.

type Object

type Object interface {
	datastore.PropertyLoadSaver
	BuildKey(ns string) (*datastore.Key, error)
}

Object is an interface that represents an entity in Datastore.

Jump to

Keyboard shortcuts

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