gorialize

package
v0.0.0-...-c4eb6d8 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package gorialize is an embedded database that stores Go structs serialized to gobs

Package gorialize is an embedded database that stores Go structs serialized to gobs

Package gorialize is an embedded database that stores Go structs serialized to gobs

Package gorialize is an embedded database that stores Go structs serialized to gobs

Package gorialize is an embedded database that stores Go structs serialized to gobs

Package gorialize is an embedded database that stores Go structs serialized to gobs

Package gorialize is an embedded database that stores Go structs serialized to gobs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShowAll

func ShowAll(dirPath string) error

ShowAll prints the content of all gob files in a directory to the console. It does not need the corresponding struct to decode the gob files.

func ShowOne

func ShowOne(dirPath string, filename string) error

ShowOne prints a gob file's contents to the console. It does not need the corresponding struct to decode the gob file.

Types

type Directory

type Directory struct {
	Path         string
	Encrypted    bool
	Key          *[32]byte
	Log          bool
	Index        Index
	IndexLogPath string
}

Directory exposes methods to read and write serialized data inside a base directory.

func NewDirectory

func NewDirectory(config DirectoryConfig) *Directory

NewDirectory returns a new Directory struct for the given configuration.

func (Directory) Create

func (dir Directory) Create(resource interface{}) error

Create creates a new serialized resource and sets its ID.

func (Directory) Delete

func (dir Directory) Delete(resource interface{}) error

Delete deletes a serialized resource.

func (Directory) DeleteAll

func (dir Directory) DeleteAll(resource interface{}) error

DeleteAll deletes all serialized resources of the given type.

func (Directory) Find

func (dir Directory) Find(slice interface{}, clauses ...Where) error

Find finds all serialized resource of the given slice's element type matching all provided WHERE clauses and appends them to the slice.

func (Directory) FindCB

func (dir Directory) FindCB(resource interface{}, callback func(resource interface{}), clauses ...Where) error

FindCB finds all serialized resource of the given type matching all provided WHERE clauses and calls the provided callback function on each.

func (Directory) GetOwner

func (dir Directory) GetOwner(resource interface{}, owner interface{}) error

GetOwner reads the serialized resource which owns the given resource. The resource needs to have an addressable owner ID int field which follows a 'FooID' naming convention where 'Foo' is the owner type.

func (Directory) Read

func (dir Directory) Read(resource interface{}, id int) error

Read reads the serialized resource with the given ID.

func (Directory) ReadAll

func (dir Directory) ReadAll(slice interface{}) error

ReadAll reads all serialized resources of the given slice's element type and appends them to the slice.

func (Directory) ReadAllCB

func (dir Directory) ReadAllCB(resource interface{}, callback func(resource interface{})) error

ReadAllCB reads all serialized resources of the given type and calls the provided callback function on each.

func (Directory) Replace

func (dir Directory) Replace(resource interface{}) error

Replace replaces a serialized resource.

func (Directory) ReplayIndexLog

func (dir Directory) ReplayIndexLog()

func (Directory) ResetCounter

func (dir Directory) ResetCounter(resource interface{}) error

ResetCounter resets the resource counter to zero

type DirectoryConfig

type DirectoryConfig struct {
	Path       string
	Encrypted  bool
	Passphrase string
	Log        bool
}

DirectoryConfig holds parameters to be passed to NewDirectory().

type Index

type Index struct {
	KV map[string][]int
	VK map[string][]string
}

func NewIndex

func NewIndex() Index

type Query

type Query struct {
	FatalError   error
	Dir          Directory
	Operation    string
	Writer       bytes.Buffer
	GobBuffer    []byte
	ResourceType reflect.Type
	Model        string
	Resource     interface{}
	ID           int
	Counter      int
	CounterPath  string
	MetadataPath string
	ResourcePath string
	DirPath      string
	SafeIOPath   bool
	DirFileInfo  []os.FileInfo
	WhereClauses []Where
	MatchedIDs   []int
	IndexUpdates []string
}

func (*Query) ApplyWhereClauses

func (q *Query) ApplyWhereClauses()

func (*Query) BuildCounterPath

func (q *Query) BuildCounterPath()

func (*Query) BuildCustomDirPath

func (q *Query) BuildCustomDirPath(subdir string)

func (*Query) BuildDirPath

func (q *Query) BuildDirPath()

func (*Query) BuildMetadataPath

func (q *Query) BuildMetadataPath()

func (*Query) BuildResourcePath

func (q *Query) BuildResourcePath()

func (*Query) CreateMetadataDirectoryIfNotExist

func (q *Query) CreateMetadataDirectoryIfNotExist()

func (*Query) DecodeGobToResource

func (q *Query) DecodeGobToResource()

func (*Query) DecryptGobBuffer

func (q *Query) DecryptGobBuffer()

func (*Query) DeleteFromDisk

func (q *Query) DeleteFromDisk()

func (*Query) EncodeResourceToGob

func (q *Query) EncodeResourceToGob()

func (*Query) EncryptGobBuffer

func (q *Query) EncryptGobBuffer()

func (*Query) ExitIfDirNotExist

func (q *Query) ExitIfDirNotExist()

func (*Query) ExitIfResourceNotExist

func (q *Query) ExitIfResourceNotExist()

func (*Query) IncrementCounterAndSetID

func (q *Query) IncrementCounterAndSetID()

func (Query) Log

func (q Query) Log()

func (*Query) PassResourceToCallback

func (q *Query) PassResourceToCallback(callback func(resource interface{}))

func (*Query) ReadCounterFromDisk

func (q *Query) ReadCounterFromDisk()

func (*Query) ReadDirFileinfo

func (q *Query) ReadDirFileinfo()

func (*Query) ReadGobFromDisk

func (q *Query) ReadGobFromDisk()

func (*Query) ReflectModelNameFromType

func (q *Query) ReflectModelNameFromType()

func (*Query) ReflectTypeOfResource

func (q *Query) ReflectTypeOfResource()

func (*Query) SetCounterToZero

func (q *Query) SetCounterToZero()

func (*Query) ThwartIOBasePathEscape

func (q *Query) ThwartIOBasePathEscape()

func (*Query) UpdateIndex

func (q *Query) UpdateIndex(operator rune)

UpdateIndex updates the index based on operator: '+' = add, '-' = remove, 'x' = replace

func (*Query) WriteCounterToDisk

func (q *Query) WriteCounterToDisk()

func (*Query) WriteGobToDisk

func (q *Query) WriteGobToDisk()

type Where

type Where struct {
	Field  string
	Equals interface{}
	In     []interface{}
	Range  []int
	And    *Where
}

Jump to

Keyboard shortcuts

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