gofiledb

package module
v0.0.0-...-1547497 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2019 License: GPL-3.0 Imports: 15 Imported by: 1

README

GoFileDb

A basic schemaless implementation of a file system based DB client for Go. Developed while working for Next Jump.

There are a lot of reasons why a local file-system can and shall be used as a schemaless DB for micro projects. GoFileDb resembles a cache layer more than DB, since it doesn't have all the functionality that a DB would usually offer. GoFileDb works on the power of Get and Set methods.

Installation Instructions

go get https://github.com/teejays/gofiledb

Documentation

Overview

gofiledb package provides an interface between Go applications and the linux-based file system so that the filesystem can be used as a database or a caching layer.

Index

Constants

View Source
const (
	ENCODING_NONE uint = collection.ENCODING_NONE
	ENCODING_JSON uint = collection.ENCODING_JSON
	ENCODING_GOB  uint = collection.ENCODING_GOB
)
View Source
const DEFAULT_CLIENT_NUM_PARTITIONS int = 2

Variables

View Source
var ErrClientAlreadyInitialized error = fmt.Errorf("Attempted to initialie GoFileDb client more than once")

Errors

View Source
var ErrClientNotInitialized error = fmt.Errorf("GoFiledb client fetched called without initializing the client")
View Source
var ErrCollectionIsExist = collection.ErrCollectionIsExist
View Source
var ErrCollectionIsNotExist = collection.ErrCollectionIsNotExist
View Source
var ErrIndexNotImplemented = collection.ErrIndexNotImplemented
View Source
var ErrIsRepartitioning = fmt.Errorf("The system is already busy repartitioning a collection. Please try again in a while.")

Functions

func Initialize

func Initialize(p ClientInitOptions) error

Initialize setsup the package for use by an appliction. This should be called before the client can be used.

func IsNotExist

func IsNotExist(err error) bool

func Repartition

func Repartition(params RepartitionParams) error

Types

type BoolAtomic

type BoolAtomic struct {
	Val bool
	sync.RWMutex
}

func (*BoolAtomic) CompareAndSet

func (a *BoolAtomic) CompareAndSet(v bool) bool

func (*BoolAtomic) GetVal

func (a *BoolAtomic) GetVal() bool

func (*BoolAtomic) SetVal

func (a *BoolAtomic) SetVal(v bool)

type Client

type Client struct {
	ClientParams
	// contains filtered or unexported fields
}

Client is the primary object that the external application interacts with while saving or fetching data

func GetClient

func GetClient() *Client

GetClient returns the current instance of the client for the application. It panics if the client has not been initialized.

func (*Client) AddCollection

func (c *Client) AddCollection(_p CollectionProps) error

func (*Client) AddIndex

func (c *Client) AddIndex(collectionName string, fieldLocator string) error

func (*Client) Destroy

func (c *Client) Destroy() error

func (*Client) FlushAll

func (c *Client) FlushAll() error

func (*Client) Get

func (c *Client) Get(collectionName string, k Key) ([]byte, error)

func (*Client) GetFile

func (c *Client) GetFile(collectionName string, k Key) (*os.File, error)

func (*Client) GetIfExist

func (c *Client) GetIfExist(collectionName string, k Key) ([]byte, error)

func (*Client) GetIntoWriter

func (c *Client) GetIntoWriter(collectionName string, k Key, dest io.Writer) error

func (*Client) GetNewEntityID

func (c *Client) GetNewEntityID(collection string) (Key, error)

GetNewEntityID generates a unique pk.ID for the given collection

func (*Client) GetStruct

func (c *Client) GetStruct(collectionName string, k Key, dest interface{}) error

func (*Client) GetStructIfExists

func (c *Client) GetStructIfExists(collectionName string, k Key, dest interface{}) (bool, error)

func (*Client) IsCollectionExist

func (c *Client) IsCollectionExist(collectionName string) (bool, error)

func (*Client) RemoveCollection

func (c *Client) RemoveCollection(collectionName string) error

func (*Client) SaveNewEntity

func (c *Client) SaveNewEntity(collection string, entity interface{}) (Key, error)

SaveNewEntity saves a new enity

func (*Client) Search

func (c *Client) Search(collectionName string, query string) (SearchResponse, error)

func (*Client) Set

func (c *Client) Set(collectionName string, k Key, data []byte) error

func (*Client) SetStruct

func (c *Client) SetStruct(collectionName string, k Key, v interface{}) error

type ClientInitOptions

type ClientInitOptions struct {
	DocumentRoot          string
	OverwritePreviousData bool // if true, gofiledb will remove all the existing data in the document root
}

type ClientParams

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

func NewClientParams

func NewClientParams(documentRoot string) ClientParams

func (*ClientParams) GobDecode

func (p *ClientParams) GobDecode(b []byte) error

func (ClientParams) GobEncode

func (p ClientParams) GobEncode() ([]byte, error)

type CollectionProps

type CollectionProps collection.CollectionProps

type Key

type Key key.Key

func NewKey

func NewKey(i int64) Key

type RepartitionParams

type RepartitionParams struct {
	DataDirectory    string // the location of the folder which stores the partition folders
	NumPartitionsNew int    // the number of partitions that we want
}

type SearchResponse

type SearchResponse struct {
	Collection   string
	Query        string
	Error        error
	TimeTaken    time.Duration
	NumDocuments int
	Result       []interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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