db

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 13 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssertData added in v0.0.9

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

AssertData is used to for converting interface objects to map of interfaces or array of interfaces

func NewConvertFactory added in v0.0.9

func NewConvertFactory() *AssertData

NewConvertFactory for initializing AssertData

func (*AssertData) Clear added in v0.0.9

func (a *AssertData) Clear()

Clear for resetting AssertData

func (*AssertData) GetArray added in v0.0.9

func (a *AssertData) GetArray() ([]string, error)

GetArray for converting a []interface{} to []string

func (*AssertData) GetError added in v0.1.1

func (a *AssertData) GetError() error

GetError returns the any error set to AssertData

func (*AssertData) GetInt added in v0.1.1

func (a *AssertData) GetInt() (int, error)

GetInt asserts the input as int

func (*AssertData) GetMap added in v0.0.9

func (a *AssertData) GetMap() (map[string]string, error)

GetMap for converting a map[interface{}]interface{} into a map[string]string

func (*AssertData) GetString added in v0.1.1

func (a *AssertData) GetString() (string, error)

GetString asserts the input as string

func (*AssertData) Index added in v0.0.9

func (a *AssertData) Index(i int) *AssertData

Index getting an interface{} from a []interface{}

func (*AssertData) Input added in v0.0.9

func (a *AssertData) Input(o interface{}) *AssertData

Input sets a data source that can be used for assertion

func (*AssertData) Key added in v0.0.9

func (a *AssertData) Key(k string) *AssertData

Key copies initial interface object and returns a map of interfaces{} Used to easily pipe interfaces

type SQL

type SQL struct {
	v1.Cache
	v2.Query
}

SQL is the core struct for working with maps.

func NewSQLFactory added in v0.0.5

func NewSQLFactory() *SQL

NewSQLFactory creates a new empty SQL

func (*SQL) Clear

func (s *SQL) Clear() *SQL

Clear deletes all objects from Query and Cache structures

type Storage

type Storage struct {
	sync.Mutex

	SQL  *SQL
	Path string
	// contains filtered or unexported fields
}

Storage is the main object exported by DBy. It consolidates together the Yaml Data and SQL

func NewStorageFactory

func NewStorageFactory(p ...interface{}) (*Storage, error)

NewStorageFactory for creating a new Storage

func (*Storage) AddDoc added in v0.1.0

func (s *Storage) AddDoc() error

AddDoc will add a new document to the stack and will switch Active Document index to that document

func (Storage) Clear added in v0.3.3

func (c Storage) Clear()

Clear for clearing the v3 state

func (Storage) ClearLib added in v0.3.3

func (c Storage) ClearLib()

ClearLib removes all keys from the lib map

func (*Storage) Close added in v0.3.3

func (s *Storage) Close() error

Close method will do a write if InMem is false and then clear cache and buffers

func (*Storage) Delete

func (s *Storage) Delete(k string) error

Delete is a SQL wrapper that deletes the last key from a given path. For example, Delete("key-1.key-2.key-3") would first validate that the path exists, then it would export the value of GetPath("key-1.key-2") and delete the object that matches key-3

func (*Storage) DeleteAll added in v0.2.1

func (s *Storage) DeleteAll(delete bool) *Storage

DeleteAll for removing all docs

func (Storage) DeleteAllData added in v0.3.3

func (c Storage) DeleteAllData()

DeleteAllData calls PurgeAllData first and then creates a new empty array

func (Storage) DeleteBuffer added in v0.3.3

func (c Storage) DeleteBuffer()

DeleteBuffer deletes the data from the buffer array

func (Storage) DeleteData added in v0.3.3

func (c Storage) DeleteData(i int) error

DeleteData for deleting the i'th element from the data array

func (*Storage) DeleteDoc added in v0.2.0

func (s *Storage) DeleteDoc(i int) error

DeleteDoc will the document with the given index

func (*Storage) DeleteGlobal added in v0.2.1

func (s *Storage) DeleteGlobal(k string) error

DeleteGlobal is the same as Delete but will try to delete the path on all docs (if found)

func (*Storage) FindKeys added in v0.1.0

func (s *Storage) FindKeys(k string) ([]string, error)

FindKeys is a SQL wrapper that finds all the paths for a given e.g. ["key-1.test", "key-2.key-3.test"] will be returned

func (*Storage) FindKeysGlobal added in v0.2.0

func (s *Storage) FindKeysGlobal(k string) map[int][]string

FindKeysGlobal does the same as FindKeys but for all docs. Instead of returning a list of keys it returns a map with indexes from the docs and value an array of paths that was found

func (*Storage) Get

func (s *Storage) Get(k string) ([]string, error)

Get is alias of FindKeys. This function will be replaced by FindKeys in the future. For now we keep both for compatibility

func (Storage) GetAD added in v0.3.3

func (c Storage) GetAD() int

GetAD returns the current active document index

func (Storage) GetAllBuffer added in v0.3.3

func (c Storage) GetAllBuffer() []*interface{}

GetAllBuffer returns the buffer array

func (Storage) GetAllData added in v0.3.3

func (c Storage) GetAllData() []interface{}

GetAllData returns the data array

func (Storage) GetBufferFromIndex added in v0.3.3

func (c Storage) GetBufferFromIndex(i int) (*interface{}, error)

GetBufferFromIndex returns the i'th element from the buffer array

func (Storage) GetData added in v0.3.3

func (c Storage) GetData() interface{}

GetData returns the data in the c.ad index from the data array

func (Storage) GetDataFromIndex added in v0.3.3

func (c Storage) GetDataFromIndex(i int) (interface{}, error)

GetDataFromIndex returns the i'th element from the data array

func (*Storage) GetFirst

func (s *Storage) GetFirst(k string) (interface{}, error)

GetFirst is a SQL wrapper for finding the first key in the yaml hierarchy. If two keys are on the same level but under different paths, then the selection will be random

func (*Storage) GetFirstGlobal added in v0.2.0

func (s *Storage) GetFirstGlobal(k string) map[int]interface{}

GetFirstGlobal does the same as GetFirst but for all docs. Instead of returning an interface it returns a map with keys the index of the doc that a key was found and value the value of the key

func (*Storage) GetPath

func (s *Storage) GetPath(k string) (interface{}, error)

GetPath is a SQL wrapper that returns the value for a given path. Example, it would return "value-1" if "key-1.key-2" was the path asked from the following yaml --------- key-1:

key-2: value-1

func (*Storage) GetPathGlobal added in v0.2.1

func (s *Storage) GetPathGlobal(k string) map[int]interface{}

GetPathGlobal does the same as GetPath but globally for all docs

func (*Storage) ImportDocs added in v0.1.0

func (s *Storage) ImportDocs(path string, o ...bool) error

ImportDocs for importing documents

func (*Storage) InMem added in v0.3.0

func (s *Storage) InMem(m bool) *Storage

InMem for configuring db to write only in memory

func (Storage) IndexInRange added in v0.3.3

func (c Storage) IndexInRange(i int) error

IndexInRange check if index is within data array range

func (Storage) Lib added in v0.1.0

func (c Storage) Lib() map[string]int

Lib returns the lib map

func (Storage) LibIndex added in v0.3.3

func (c Storage) LibIndex(doc string) (int, bool)

LibIndex returns the index for a given doc name

func (*Storage) ListDocs added in v0.1.0

func (s *Storage) ListDocs() []string

ListDocs will return an array with all docs names

func (*Storage) MergeDBs

func (s *Storage) MergeDBs(path string) error

MergeDBs is a SQL wrapper that merges a source yaml file with the DBy local yaml file.

func (Storage) PushBuffer added in v0.3.3

func (c Storage) PushBuffer(d interface{})

PushBuffer for appending data to the buffer array

func (Storage) PushData added in v0.3.3

func (c Storage) PushData(d interface{})

PushData for appending data to the data array

func (*Storage) Read

func (s *Storage) Read() error

Read for reading the local yaml file and importing it in memory

func (Storage) RemoveDocName added in v0.3.3

func (c Storage) RemoveDocName(i int) error

RemoveDocName removes a doc from the lib

func (Storage) SetAD added in v0.3.3

func (c Storage) SetAD(i int) error

SetAD for setting new Active Document index

func (Storage) SetBufferFromIndex added in v0.3.3

func (c Storage) SetBufferFromIndex(v interface{}, i int) error

SetDataFromIndex sets to input value the i'th element from the data array

func (Storage) SetData added in v0.3.3

func (c Storage) SetData(v interface{}) error

SetData sets to input value the data in the c.ad index from the data array

func (Storage) SetDataFromIndex added in v0.3.3

func (c Storage) SetDataFromIndex(v interface{}, i int) error

SetDataFromIndex sets to input value the i'th element from the data array

func (*Storage) SetName added in v0.1.0

func (s *Storage) SetName(n string, i int) error

SetName adds a name for a document and maps with it the given doc index

func (*Storage) SetNames added in v0.1.0

func (s *Storage) SetNames(f, l string) error

SetNames can set names automatically to the documents that have the queried paths. input(f) is the first path that will be quieried input(l) is the last path

If a document has both paths, a name will be generated and will be mapped with the document's index

func (*Storage) Switch added in v0.1.0

func (s *Storage) Switch(i int) error

Switch will change Active Document (AD) to the given index

func (*Storage) SwitchDoc added in v0.1.0

func (s *Storage) SwitchDoc(n string) error

SwitchDoc for switching to a document using the documents name (if any)

func (Storage) UnsetBufferArray added in v0.3.3

func (c Storage) UnsetBufferArray()

UnsetBufferArray This sets buffer = nil

func (Storage) UnsetDataArray added in v0.3.3

func (c Storage) UnsetDataArray()

UnsetDataArray for deleting all data. This sets data = nil

func (*Storage) UpdateGlobal added in v0.1.0

func (s *Storage) UpdateGlobal(k string, i interface{}) error

UpdateGlobal is a SQL wrapper for adding/updating map structures in all documents. This will change all existing paths to the given structure (if any)

func (*Storage) Upsert

func (s *Storage) Upsert(k string, i interface{}) error

Upsert is a SQL wrapper for adding/updating map structures

func (*Storage) UpsertGlobal added in v0.1.0

func (s *Storage) UpsertGlobal(k string, i interface{}) error

UpsertGlobal is a SQL wrapper for adding/updating map structures in all documents. This will change all existing paths to the given structure and add new if the path is missing for a document

func (*Storage) Write

func (s *Storage) Write() error

Write for writing memory content to the local yaml file

Jump to

Keyboard shortcuts

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