inidb

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: ISC Imports: 9 Imported by: 0

Documentation

Overview

inidb package uses a regular ini file as a database. Ini sections are considered tables. Individual entries are considered records and are key = value pairs.

The package assumes that the user will create a single inidb per directory.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("record not found")
	ErrCreated  = errors.New("database created")
)

Functions

This section is empty.

Types

type INIDB

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

INIDB is an opaque structure that contains the database context.

func New

func New(filename string, create bool, depth int) (*INIDB, error)

New returns a new INIDB context. Depth contains the maximum number of files that are retained. Create indicates if the database should be created if it doesn't exist. If depth is negative there is no limit. If the ini file does not exist it returns an error. The inidb package assumes there is only one inidb per directory. DO NOT CREATE MULTIPLE INIDBS IN A SINGLE DIRECTORY.

func (*INIDB) Del

func (i *INIDB) Del(table, key string) error

Del remove a record from a table.

func (*INIDB) DelTable

func (i *INIDB) DelTable(table string) error

DelTable deletes an entire table including all records.

func (*INIDB) Get

func (i *INIDB) Get(table string, key string) (string, error)

Get returns a record from table. If the record does not exist ErrNotFound is returned.

func (*INIDB) NewTable

func (i *INIDB) NewTable(table string)

NewTable creates a new table.

func (*INIDB) Records

func (i *INIDB) Records(table string) map[string]string

Records returns a copy of all records in the given table.

func (*INIDB) Save

func (i *INIDB) Save() error

Save flushes current in memory database back to disk. The process is as follows:

  1. Check if the database is dirty and abort process if it isn't
  2. Create temporary file that contains all memory tables and records
  3. Backup original file
  4. Rename temporary file to the original file name

This creates a running log of flushes.

NOTE: currently there is no file count limiter.

func (*INIDB) Set

func (i *INIDB) Set(table, key, value string) error

Set creates/overwrites a record in table. If table does not exist ErrNotFound is returned.

func (*INIDB) Tables

func (i *INIDB) Tables() []string

Tables returns a copy of all tables in the inidb.

Jump to

Keyboard shortcuts

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