db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 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 {
	Query v2.Cache
	Cache v1.Cache
}

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
	Data []interface{}
	Lib  map[string]int
	AD   int
	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) 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) 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 alias of Get. This function will replace Get in the future since this name for finding keys makes more sense For now we keep both for compatibility

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 a SQL wrapper that finds all the paths for a given e.g. ["key-1.test", "key-2.key-3.test"] will be returned if "test" was the key asked from the following yaml ---------

key-1:

test: someValue-1

key-2:

key-3:
	test: someValue-2

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) 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) Read

func (s *Storage) Read() error

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

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) 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 and add new if the path is missing for a document

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