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
- Variables
- func CheckForOne(dbhandle Dbhandle, kind string, name string) (int32, error)
- func ChkNilArray(obj interface{})
- func ConnectDB(dbEngine string, params interface{}) (*sql.DB, error)
- func DecodeBlob(data []byte, obj interface{}) error
- func EncodeBlob(obj interface{}) ([]byte, error)
- func EncodeToJSON(obj interface{}) (string, error)
- func WalkMapForNil(r interface{}) interface{}
- type DataStore
- func (ds *DataStore) Delete(key_type string, key string)
- func (ds *DataStore) DeleteLogInfo(id int) error
- func (ds *DataStore) Get(key_type string, key string) (interface{}, bool)
- func (ds *DataStore) GetList(key_type string) []string
- func (ds *DataStore) GetLogInfo(id int) (interface{}, error)
- func (ds *DataStore) GetLogInfoList() map[int]interface{}
- func (ds *DataStore) Load(dsFile string) error
- func (ds *DataStore) PurgeLogInfoBefore(id int) (int64, error)
- func (ds *DataStore) Save(dsFile string) error
- func (ds *DataStore) Set(key_type string, key string, val interface{})
- func (ds *DataStore) SetLogInfo(obj interface{}, log_id ...int) error
- type Dbhandle
- type ResRow
Constants ¶
const MySQLTimeFormat = "2006-01-02 15:04:05"
Format to use for dates and times for MySQL.
Variables ¶
var Dbh *sql.DB
The database handle.
Functions ¶
func CheckForOne ¶ added in v0.5.0
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
Connect to a database with the database name and a map of connection options. Currently supports MySQL.
func DecodeBlob ¶ added in v0.5.0
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
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 EncodeToJSON ¶ added in v0.5.1
Encode an object to a JSON string.
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) DeleteLogInfo ¶ added in v0.5.1
func (*DataStore) GetLogInfo ¶ added in v0.5.1
Get a log_info by id.
func (*DataStore) GetLogInfoList ¶ added in v0.5.1
Get all the log infos currently stored
func (*DataStore) PurgeLogInfoBefore ¶ added in v0.5.1
func (*DataStore) SetLogInfo ¶ added in v0.5.1
Set a log_info in the data store. Unlike most of these objects, log infos are stored and retrieved by id, since they have no useful names.
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