data_store

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2014 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package data_store provides data store functionality. The data store is kept in memory, but optionally the data store may be saved to a file to provide a perisistent data store. This uses go-cache (https://github.com/pmylund/go-cache) for storing the data.

The methods that set, get, and delete key/value pairs also take a `key_type` argument that specifies what kind of object it is.

General functions for goiardi database connections, if running in that mode. Database engine specific functions are in their respective source files.

MySQL specific functions for goiardi database work.

Index

Constants

View Source
const MySQLTimeFormat = "2006-01-02 15:04:05"

Format to use for dates and times for MySQL.

Variables

View Source
var Dbh *sql.DB

The database handle.

Functions

func CheckForOne added in v0.5.0

func CheckForOne(dbhandle Dbhandle, kind string, name string) (int32, error)

Check for one object of the given type identified by the given name. For this function to work, the underlying table MUST have its primary text identifier be called "name".

func ChkNilArray added in v0.5.0

func ChkNilArray(obj interface{})

When restoring an object from either the in-memory data store after it has been saved to disk, or loading an object from the database with gob encoded data structures, empty slices are encoded as "null" when they're sent out as JSON to the client. This makes the client very unhappy, so those empty slices need to be recreated again. Annoying, but it's how it goes.

func ConnectDB added in v0.5.0

func ConnectDB(dbEngine string, params interface{}) (*sql.DB, error)

Connect to a database with the database name and a map of connection options. Currently supports MySQL.

func DecodeBlob added in v0.5.0

func DecodeBlob(data []byte, obj interface{}) error

Decode the data encoded with EncodeBlob that was stored in the database so it can be loaded back into a goiardi object. The 'obj' in the arguments *must* be the address of the object receiving the blob of data (e.g. data_store.DecodeBlob(data, &obj).

func EncodeBlob added in v0.5.0

func EncodeBlob(obj interface{}) ([]byte, error)

Encode a slice or map of goiardi object data to save in the database. Pass the object to be encoded in like data_store.EncodeBlob(&foo.Thing).

func WalkMapForNil added in v0.3.0

func WalkMapForNil(r interface{}) interface{}

Walk through the given map, searching for nil slices to create. This does not handle all possible cases, but it *does* handle the cases found with the chef objects in goiardi.

Types

type DataStore

type DataStore struct {
	// contains filtered or unexported fields
}

Main data store.

func New

func New() *DataStore

Create a new data store instance, or return an already created one.

func (*DataStore) Delete

func (ds *DataStore) Delete(key_type string, key string)

func (*DataStore) Get

func (ds *DataStore) Get(key_type string, key string) (interface{}, bool)

func (*DataStore) GetList

func (ds *DataStore) GetList(key_type string) []string

Return a list of all objects of the given type.

func (*DataStore) Load added in v0.3.0

func (ds *DataStore) Load(dsFile string) error

Load the frozen data store from disk.

func (*DataStore) Save added in v0.3.0

func (ds *DataStore) Save(dsFile string) error

Freeze and save the data store to disk.

func (*DataStore) Set

func (ds *DataStore) Set(key_type string, key string, val interface{})

type Dbhandle added in v0.5.0

type Dbhandle interface {
	Prepare(query string) (*sql.Stmt, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Query(query string, args ...interface{}) (*sql.Rows, error)
	Exec(query string, args ...interface{}) (sql.Result, error)
}

Interface for db handle types that can execute queries

type ResRow added in v0.5.0

type ResRow interface {
	Scan(dest ...interface{}) error
}

Interface for rows returned by Query, or a single row returned by QueryRow. Used for passing in a db handle or a transaction to a function.

Jump to

Keyboard shortcuts

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