anom

package module
v0.0.0-...-e8c38e2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2016 License: BSD-3-Clause Imports: 6 Imported by: 1

README

anom

GoDoc Build Status codebeat badge

go get github.com/Bogdanp/anom

Package anom is a simple "object mapper" for appengine datastore that provides some convenience functions for dealing with datastore entities.

Check out the example directory for usage examples.

Documentation

Overview

Package anom is a simple "object mapper" for appengine datastore and that provides some convenience functions for dealing with datastore entities.

package app

import (
	"github.com/Bogdanp/anom"
)

type Post struct {
	anom.Meta

	Title   string
	Content string
}

Index

Constants

View Source
const (
	// StateActive is the state of Model instances that have been persisted.
	StateActive = "active"
	// StateDeleted is the state of Model instances that have been deleted.
	StateDeleted = "deleted"
)

Variables

View Source
var (
	// ErrMissingKey is the error that is returned when a Model lacks a
	// key.  This can be returned if you attempt to Delete a Model that
	// hasn't been saved yet or if you attempt to Get a Model that
	// doesn't have a Key.
	ErrMissingKey = errors.New("anom: model does not have a Key")
)

Functions

func Delete

func Delete(ctx context.Context, m Model) error

Delete soft deletes a Model from datastore.

func Get

func Get(ctx context.Context, m Model, options ...Option) error

Get retrieves a Model from datastore by its id.

func Put

func Put(ctx context.Context, m Model, options ...Option) error

Put stores a Model to datastore.

func Query

func Query(kind string) *datastore.Query

Query returns a new datastore query for the given kind that will ignore deleted entities. Note that querying does not hydrate Meta Keys and Parents so you will have to do that manually.

Types

type Meta

type Meta struct {
	Key       *datastore.Key `json:"-" datastore:"-"`
	Parent    *datastore.Key `json:"-" datastore:"-"`
	State     string         `json:"-"`
	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `json:"updatedAt"`
	DeletedAt time.Time      `json:"deletedAt"`
}

Meta is the struct that all Model structs must embed. It extends entities with metadata about when they were created, last updated and deleted as well as their current state and their Key.

type User struct {
    anom.Meta

    Username string
}

type Model

type Model interface {
	// contains filtered or unexported methods
}

Model is the interface that all Model structs automatically implement when they embed Meta.

type Option

type Option func(Model)

Option is the type of functional Model options.

func WithIntID

func WithIntID(ctx context.Context, id int64) Option

WithIntID is an Option for assigning a datastore Key with the given int64 id to a Model's Meta.

func WithKey

func WithKey(k *datastore.Key) Option

WithKey is an Option for assigning a datastore Key to a Model's Meta.

func WithParent

func WithParent(k *datastore.Key) Option

WithParent is an Option for assigning a datastore Key to a Model's Meta as that Model's parent.

p := &Post{Content: "Hello"}
Put(ctx, p, WithParent(u.Key))

func WithStringID

func WithStringID(ctx context.Context, id string) Option

WithStringID is an Option for assigning a datastore Key with the given string id to a Model's Meta.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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