tinyindexdb

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2024 License: MIT Imports: 7 Imported by: 0

README

tiny-index-db

A tiny key-value disk-based Golang database that is capable of querying one type of indices

Documentation

TODO

Features

  • Write locks to avoid race conditions
  • Concurrent non-blocking reading
  • Tables to keep your little database organised

Example usage

Create a new table
tinyindexdb.NewTable("MyTable")

(returns an error only on the occurrence of an I/O error)

Destroy (remove) a table
tinyindexdb.DestroyTable("MyTable")

(returns an error only on the occurrence of an I/O error)

Check if a table exists
tinyindexdb.TableExists("NotMyTable")

(returns a boolean depending on the situation)

Query a record
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.
Write/update a record
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.

Delete a record
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.
Clear the datababse cache
tinyindexdb.ClearCache()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache

func ClearCache()

func DeleteRecord

func DeleteRecord(table_name, index_name string) error

func DestroyTable

func DestroyTable(table_name string) error

func NewTable

func NewTable(table_name string) error

func Query

func Query(table_name, index_name string) (map[string]interface{}, error)

func TableExists

func TableExists(table_name string) bool

func Write

func Write(table_name, index_name string, data map[string]interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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