Categorygithub.com/rubanbydesign/go-aedstorm
modulepackage
0.0.0-20230710092934-ab2917f56672
Repository: https://github.com/rubanbydesign/go-aedstorm.git
Documentation: pkg.go.dev

# README

GoDoc Build Status codecov

This is an ORM like package which makes working with App Engine datastore entities in go a bit easier. The name aedstorm stands for App Engine DataSTore ORM.

It makes working with the datastore and basic data structs quite simple.

Example

import (
	"encoding/json"
	"net/http"

	"google.golang.org/appengine"
	aedstorm "github.com/rubanbydesign/go-aedstorm"
)

type MyData struct {
	ID, Value string
}

func myHandler(w http.ResponseWriter, r *http.Request) {

	ctx := appengine.NewContext(r)

	// Save a new entity.
	d := &MyData{ID: "foo", Value: "bar"}
	if err := aedstorm.NewModel(&d).WithContext(ctx).Save(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	dd := &MyData{ID: "foo"}
	if err := aedstorm.NewModel(&dd).WithContext(ctx).Load(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	// dd.Value  will now equal d.Value after the load.
	w.Header.Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(&dd)
}

I'm planning on adding more documentation in the future, including some more advanced interfaces which you can implement on a model, and queries, but for now this should give you an idea how easy it is to get going.

Planned improvements

  • Better documentation, more basic examples
  • More documentation around current interfaces which can be implemented
  • Add support for loading/saving related entities

# Functions

Copy copies one interface into the other doing type checking to make sure it's safe.
NewModel returns an initialized data model.
NewQuery returns a new query based off the type of m.
NewUUID creates a new uuid v4.
SetMockQueryResult sets the query GetAll() result to be the values given.

# Constants

TagName is the tag name where we look for custom tag values, like "id".

# Variables

Standardized error messages.
Standardized error messages.
Standardized error messages.
Standardized error messages.
Standardized error messages.

# Structs

DataModel is a ORM styled structure for saving and loading entities.
Query is a struct which implements a subset of the "datastore.Query" interface and is mockable.

# Interfaces

EntityError is an interface which returns an error.
EntityID is an interface returns the int64 ID for the datastore struct.
EntityName is an interface which defines the entity name of the data to be stored in the datastore.
Model is an interface for datastore entities.
OnCache is an interface which defines a callback which is run after a entity is successfully cached.
OnDelete is an interface which defines a callback which is run after a entity is successfully deleted.
OnSave is an interface which defines a callback which is run after a entity is successfully saved.
OnUncache is an interface which defines a callback which is run after a entity is successfully removed from cache.
SetID is an interface, which if defined, allows the model to set it's own ID.

# Type aliases

UUID is a v4 Universally unique identifier.