dirfilestore

package
v0.0.0-...-955908a Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultListLimit = 100

DefaultListLimit is the default max nr of items to return in list

Variables

This section is empty.

Functions

This section is empty.

Types

type DirFileStore

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

DirFileStore is a crude little file based Directory store Intended as a testing MVP for the directory service Implements the IDirStore interface

func NewDirFileStore

func NewDirFileStore(jsonFilePath string) *DirFileStore

NewDirFileStore creates a new directory file store instance

filePath path to JSON store file

func (*DirFileStore) AutoSaveLoop

func (store *DirFileStore) AutoSaveLoop()

AutoSaveLoop periodically saves changes to the directory

func (*DirFileStore) Close

func (store *DirFileStore) Close()

Close the store

func (*DirFileStore) DeleteAll

func (store *DirFileStore) DeleteAll()

DeleteAll empties the store. Intended for etsting.

func (*DirFileStore) Get

func (store *DirFileStore) Get(thingID string) (interface{}, error)

Get a document by its ID

id of the thing to look up

Returns an error if it doesn't exist

func (*DirFileStore) List

func (store *DirFileStore) List(offset int, limit int, aclFilter func(thingID string) bool) []interface{}

List returns a list of documents

offset is the offset in the document list that is sorted by document ID
limit is the maximum nr of documents to return or 0 for the default
aclFilter filters the things by ID. Use nil to ignore.

This returns an empty list if offset is equal or larger than the available nr of documents

func (*DirFileStore) Open

func (store *DirFileStore) Open() error

Open the store Returns error if it can't be opened or already open

func (*DirFileStore) Patch

func (store *DirFileStore) Patch(id string, src map[string]interface{}) error

Patch a document Returns an error if it doesn't exist

func (*DirFileStore) Query

func (store *DirFileStore) Query(jsonPath string, offset int, limit int,
	aclFilter func(thingID string) bool) ([]interface{}, error)

Query for documents using JSONPATH Eg `$[? @.properties.deviceType=="sensor"]`

jsonPath contains the query
offset contains the offset in the list of results, sorted by ID
limit contains the maximum or of responses, 0 for the default 100

func (*DirFileStore) Remove

func (store *DirFileStore) Remove(id string)

Remove a document from the store Also succeeds if the document doesn't exist

func (*DirFileStore) Replace

func (store *DirFileStore) Replace(id string, document map[string]interface{}) error

Replace a document The document does not have to exist

func (*DirFileStore) Size

func (store *DirFileStore) Size() int

Size returns the number of items in the store

Jump to

Keyboard shortcuts

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