dalgo2datastore

package module
v0.0.105 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 12 Imported by: 1

README

github.com/dal-go/dalgo2datastore

Bridge of Google Cloud Datastore API for github.com/dal-go/dalgo interface.

This uses cloud.google.com/go/datastore package.

Why "cloud.google.com/go/datastore" and not "google.golang.org/appengine/v2/datastore"?

The difference between the two Go packages cloud.google.com/go/datastore and google.golang.org/appengine/v2/datastore lies in the Google Cloud products they are designed to work with and their functionality.

cloud.google.com/go/datastore:

This package is the official Go client library for Google Cloud Datastore, which is a highly-scalable, NoSQL database for web and mobile applications provided by Google Cloud Platform. It can be used with various Google Cloud products and services, not just App Engine. The package enables your application to interact with the Datastore API, allowing you to store, query, and manage data.

The cloud.google.com/go/datastore package is recommended for new projects that require Datastore functionality. It supports all the features of the Datastore API, and works with both App Engine standard and flexible environments, as well as other environments like Kubernetes Engine or Compute Engine.

google.golang.org/appengine/v2/datastore:

This package is part of the App Engine SDK for Go and is designed specifically for use with the App Engine Standard Environment. It provides a slightly different API for working with Datastore compared to the cloud.google.com/go/datastore package. The package is tailored to the App Engine environment, which means it may not be suitable for use outside of App Engine or in newer runtime environments like the second generation of the App Engine standard environment.

TL/DR:

The cloud.google.com/go/datastore package is recommended for new projects as it is more versatile and works across various Google Cloud products and services, whereas the google.golang.org/appengine/v2/datastore package is primarily meant for use with the App Engine standard environment.

Similar projects

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// LoggingEnabled a flag to enable or disable logging inside GAE DAL
	LoggingEnabled = true // TODO: move to Context.WithValue()

	// NewIncompleteKey creates new incomplete key.
	NewIncompleteKey = datastore.IncompleteKey

	// NewKey creates new key.
	NewKey = datastore.IDKey
)
View Source
var ErrEmptyKind = errors.New("record holder returned empty kind")

ErrEmptyKind indicates record holder returned empty kind

View Source
var Put = func(c context.Context, client *datastore.Client, key *datastore.Key, val interface{}) (*datastore.Key, error) {
	if val == nil {
		panic("val == nil")
	}
	var err error
	isPartialKey := key.Incomplete()
	if LoggingEnabled {
		buf := new(bytes.Buffer)
		if err = logEntityProperties(buf, fmt.Sprintf("dbPut(%v) => properties:", key2str(key)), val); err != nil {
			log.Errorf(c, "Put(%v) failed to log properties: %v", key2str(key), err)
		} else {
			log.Debugf(c, buf.String())
		}
	}
	if key, err = client.Put(c, key, val); err != nil {
		return key, fmt.Errorf("failed to put to db (key=%v): %w", key2str(key), err)
	} else if LoggingEnabled && isPartialKey {
		log.Debugf(c, "dbPut() inserted new record with key: "+key2str(key))
	}
	return key, err
}

Put saves record to datastore

View Source
var PutMulti = func(c context.Context, client *datastore.Client, keys []*datastore.Key, vals interface{}) ([]*datastore.Key, error) {
	if LoggingEnabled {

		logKeys(c, "dbPutMulti", "", keys)
	}
	return client.PutMulti(c, keys, vals)
}

PutMulti saves multipe entities to datastore

Functions

func CleanProperties

func CleanProperties(properties []datastore.Property, filters map[string]IsOkToRemove) (filtered []datastore.Property, err error)

CleanProperties removes properties in place and returns filtered slice

func IsDuplicate

func IsDuplicate(_ datastore.Property) bool

IsDuplicate indicates property is duplicate

func IsEmptyByteArray

func IsEmptyByteArray(p datastore.Property) bool

IsEmptyByteArray returns true of property value is nil or empty byte array

func IsEmptyJSON

func IsEmptyJSON(p datastore.Property) bool

IsEmptyJSON returns true if property value is empty string or empty array or empty object

func IsEmptyString

func IsEmptyString(p datastore.Property) bool

IsEmptyString returns true if property value iz empty string

func IsEmptyStringOrSpecificValue

func IsEmptyStringOrSpecificValue(v string) func(p datastore.Property) bool

IsEmptyStringOrSpecificValue returns true if property value is empty string or has specific value

func IsFalse

func IsFalse(p datastore.Property) bool

IsFalse returns true if propertry value is false

func IsObsolete

func IsObsolete(_ datastore.Property) bool

IsObsolete used for obsolete properties

func IsZeroBool

func IsZeroBool(p datastore.Property) bool

IsZeroBool returns true if property value false

func IsZeroFloat

func IsZeroFloat(p datastore.Property) bool

IsZeroFloat returns true if property value 0.0

func IsZeroInt

func IsZeroInt(p datastore.Property) bool

IsZeroInt returns true if property value is 0

func IsZeroTime

func IsZeroTime(p datastore.Property) bool

IsZeroTime returns true of property value iz zero time

func NewDatabase

func NewDatabase(ctx context.Context, projectID string) (db dal.DB, err error)

NewDatabase create database provider to Google Datastore

Types

type IsOkToRemove

type IsOkToRemove func(p datastore.Property) bool // TODO: Open source + article?

IsOkToRemove checks if it's OK to remove property value

type SaverWrapper

type SaverWrapper struct {
}

SaverWrapper used to serialize struct to properties on saving

func (SaverWrapper) Load

func (wrapper SaverWrapper) Load([]datastore.Property) (err error)

Load loads props

func (SaverWrapper) Save

func (wrapper SaverWrapper) Save() (props []datastore.Property, err error)

Save saves props

Jump to

Keyboard shortcuts

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