memzy

package module
v0.5.1-0...-788b3fc Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: MIT Imports: 1 Imported by: 0

README

Memzy

Travis build status Maintainability Test Coverage FOSSA Status

A simple object persistance inferface for golang.

Minimum requirements

go 1.13.x

Usage

Prequisite: add json tags to any objects you want to store.

type Bob {
    Name string `json:"name"` // in our examples this will be the primary key
    Height int  `json:"height"`
}
DynamoDB client
import "github.com/ace-teknologi/memzy/dynamodb"

...

c := dynamodb.New("BOB_STORAGE")
Memory client

The memory client is good for testing.

import "github.com/ace-teknologi/memzy/memory"

...

c := memory.New("name")
Use the interface

Generally I don't use the above clients directly. Instead I use the interface which enables me to switch implementations in testing.

import (
    "os"

    "github.com/ace-teknologi/memzy"
    "github.com/ace-teknologi/memzy/dynamodb"
    "github.com/ace-teknologi/memzy/memory"
)

var memzyClient memzy.memzy

func init() {
    if os.Getenv == "PRODUCTION" {
        memzyClient = dynamodb.New("BOB_STORAGE")
    } else {
        memzyClient = memory.New("name")
    }
}

GetItem
var rdj Bob
memzyClient.GetItem(rdj, map[string]interface{}{"Name": "Robert Downey Jr."})
fmt.Printf("Robert Downey Jr is %d cm tall", rdj.Height) // Robery Downey Jr. is 173 cm tall
PutItem
var rnm = &Bob{
    Name: "Robert Nesta Marley, OM",
    Height: 170,
}
memzyClient.PutItem(rnm)
NewIter

This has basically no features, just the ability to iterate over everything you have stored.

iter := memzyClient.NewIter()
// do stuff

Warning: the API of this pre-1.0 library is unstable. It is recommended to use dependency management.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("Item not found")

ErrNotFound is returned if you try to get an item that doesn't exist

Functions

This section is empty.

Types

type Iter

type Iter interface {
	// Current unmarshals the object at the current pointer into the provided object
	Current(interface{}) error
	// Err returns the error that cause Next() to fail
	Err() error
	// Next moves the pointer along if possible, else returns false
	Next() bool
}

Iter provides an interface to loop through a subset of objects

type Memzy

type Memzy interface {
	// GetItem retrieves and unmarshals the object described by the key into the provided object
	GetItem(interface{}, map[string]interface{}) error
	// PutItem stores the object
	PutItem(interface{}) error
	// NewItem returns an Iter containing all of the objects that satisfy the conditions provided
	NewIter(...interface{}) Iter
}

Memzy provides an interface between go objects and persistence layers

Current backends that implement this: - dynamodb - memory

Directories

Path Synopsis
Package dynamodb provides a library that uses DynamoDB to store your go types.
Package dynamodb provides a library that uses DynamoDB to store your go types.
Package memory provides an in-memory key value store.
Package memory provides an in-memory key value store.

Jump to

Keyboard shortcuts

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