TODO
- Write locks to avoid race conditions
- Concurrent non-blocking reading
- Tables to keep your little database organised
go get -u github.com/oddmario/tiny-index-db
import tinyindexdb "github.com/oddmario/tiny-index-db"
...
tinyindexdb.NewTable("MyTable")
(returns an error only on the occurrence of an I/O error)
tinyindexdb.DestroyTable("MyTable")
(returns an error only on the occurrence of an I/O error)
tinyindexdb.TableExists("NotMyTable")
(returns a boolean depending on the situation)
tinyindexdb.Query("MyTable", "MyRecordIndex")
returns:
- a
map[string]interface{}
if the record exists in the table. - a
the specified table does not exist
error if MyTable does not exist. - a
the specified record does not exist
error if MyRecordIndex does not exist. - a
corrupted record data
error if the record has corrupted JSON data.
tinyindexdb.Query("MyTable", "MyRecordIndex", map[string]interface{}{
"name": "mario",
"message": "i like pianos",
"timestamp": time.Now().Unix(),
})
(returns a the specified table does not exist
error if MyTable does not exist)
Note that at the moment, for updating a record, you still need to pass the whole map[string]interface{}
. A proper UpdateRecord()
function may be available in the future.
tinyindexdb.DeleteRecord("MyTable", "MyRecordIndex")
returns:
- an error on the occurrence of an I/O error
- a
the specified record does not exist
error if MyRecordIndex does not exist.
tinyindexdb.ClearCache()