/mstore

In-memory storage management system for embedded data storage

Primary LanguageGoBSD 2-Clause "Simplified" LicenseBSD-2-Clause

mstore

Go

In-memory storage management system for embedded data storage.

As an example of application, mstore can be used as the core of a cache system, or simply as an embedded database.

mstore uses an indexing system to optimize operations performance. mstore can manage multiple documents on the same index, but it is not possible to have several documents with the same key (the key is unique and is used to reference a document).

					      +-------+             data memory slot
					      |       |            +--------+-----------+
				       index  |       |            |        |           |
			     +-------> memory | Index +----------->+ Key_i  | Data      |
			     |         slot   |   01  |            |        |           |
			     |                |       |            +--------+-----------+
			     |                +-------+
			     |                |       |
			     |                |       |
			     |                |       |
+-----------+                |                |       |
|           |                |                |       |
| Data      +----------------+                +-------+
|           | hash function                   |       |            +--------+-----------+             +--------+----------+
+-----------+                                 |       |            |        |           |             |        |          |
					      | Index +----------->+ Key_j  |  Data     +------------>+ Key_k  | Data     |
					      |   ..  |            |        |           |             |        |          |
					      |       |            +--------+-----------+             +--------+----------+
					      +-------+
					      |       |
					      |       |
					      |       |
					      |       |
					      |       |
					      +-------+
					      |       |
					      |       |
					      |       |
					      +       +

Download

go get github.com/PierreKieffer/mstore

Usage

import(
	"github.com/PierreKieffer/mstore"
)

Initialize storage

s := mstore.InitStorage()

By default, the storage is built with 1000 indexes,

It is possible to configure the maximum number of indexes that make up the storage

s := mstore.InitStorage(10)

Document type

mstore uses a Document type :

type Document struct {
        Key  string
        Data interface{}
}

Documents are referenced by document key which must be unique.

If no custom key is passed, a key is generated in UnixNano format.

Insert

var data interface{} 
document := mstore.Document{Key: "custom-key", Data: data}
err = mstore.Insert(s, document)
if err != nil {
	fmt.Println(err)
}

Update

err = mstore.Update(s, document)
if err != nil {
	fmt.Println(err)
}

Delete

err := mstore.Delete(s, key)
if err != nil {
	fmt.Println(err)
}

Find

doc, err := mstore.Find(s, key)
if err != nil {
	fmt.Println(err)
}