persistence

package
v1.1.11 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 20 Imported by: 10

Documentation

Overview

Package persistence contains interfaces for various design patterns that work with data. Contains various persistence implementations (InMemory and File –persistences). These are "abstract" persistences, which only connect to data sources and do not implement the operations and methods for working the data. The classes that extend these persistences must implement this logic on their own. Identifiable Persistences work with Identifiable objects, which have primary keys. A few standard operations are defined by default for these objects: reading arrays and data pages; searching for an object by its id; and creating, updating, and deleting records of objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneObject

func CloneObject(item interface{}, proto reflect.Type) interface{}

CloneObject is clones object function Parameters:

  • item interface{} an object to clone

Return interface{} copy of input item

func CloneObjectForResult added in v1.0.1

func CloneObjectForResult(src interface{}, proto reflect.Type) interface{}

CloneObjectForResult is clones object for result function Parameters:

  • item interface{} an object to clone -proto reflect.Type type of returned value, need for detect object or pointer returned type

Return interface{} copy of input item

func CompareValues

func CompareValues(value1 interface{}, value2 interface{}) bool

CompareValues are ompares two values Parameters:

  • value1 interface{} an object one for compare
  • value2 interface{} an object two for compare

Return bool true if value1 equal value2 and false otherwise

func FromIds added in v1.0.1

func FromIds(ids []string) []interface{}

FromIds method convert ids string array to array of interface{} object Parameters:

  • ids - []string array of ids

Return []interface{} array of ids

func GenerateObjectId

func GenerateObjectId(item *interface{})

GenerateObjectId is generates a new id value when it's empty Parameters:

  • item *interface{} an pointer on object to set id property

Results saved in input object

func GetObjectId

func GetObjectId(item interface{}) interface{}

Get object Id value Parameters:

  • item interface{} an object to read property from.

Returns interface{} the property value or nil if property doesn't exist or introspection failed.

func GetProperty

func GetProperty(obj interface{}, name string) interface{}

Gets value of object property specified by its name. Parameters:

  • obj interface{} an object to read property from.
  • name string a name of the property to get.

Returns interface{} the property value or null if property doesn't exist or introspection failed.

func SetObjectId

func SetObjectId(item *interface{}, id interface{})

SetObjectId is set object Id value Parameters:

  • item *interface{} an pointer on object to set id property
  • id interface{} id value for set

Results saved in input object

func SetProperty

func SetProperty(obj interface{}, name string, value interface{})

Sets value of object property specified by its name. If the property does not exist or introspection fails this method doesn't do anything and doesn't any throw errors. Parameters:

  • obj interface{} an object to write property to. name string a name of the property to set.
  • value interface{} a new value for the property to set.

func ToPublicArray added in v1.0.1

func ToPublicArray(values []interface{}) []map[string]interface{}

ToPublicArray method convert array of interface{} object to array of map[string]interface{} Parameters

  • value - []interface{} input object to convert

Return []map[string]interface{} converted map array

func ToPublicMap added in v1.0.1

func ToPublicMap(value interface{}) map[string]interface{}

ToPublicMap method convert interface{} object to map[string]interface{} Parameters

  • value - interface{} input object to convert

Return map[string]interface{} converted object to map

Types

type FilePersistence

type FilePersistence struct {
	MemoryPersistence
	Persister *JsonFilePersister
}

Abstract persistence component that stores data in flat files and caches them in memory.

FilePersistence is the most basic persistence component that is only able to store data items of any type. Specific CRUD operations over the data items must be implemented in child structs by accessing fp._items property and calling Save method.

see MemoryPersistence see JsonFilePersister

Configuration parameters

  • path - path to the file where data is stored

References

- *:logger:*:*:1.0 (optional) ILogger components to pass log messages

Example

type MyJsonFilePersistence struct {
	FilePersistence
}
    func NewMyJsonFilePersistence(path string) *NewMyJsonFilePersistence {
		prototype := reflcet.TypeOf(MyData{})
		return &NewFilePersistence(prototype, NewJsonPersister(prototype, path))
    }

	func (c * FilePersistence) GetByName(correlationId string, name string) (item MyData, err error){
		for _,v := range c._items {
			if v.Name == name {
				item = v.(MyData)
				break
			}
		}
        return item, nil
    }

    func (c *FilePersistence) Set(correlatonId string, item MyData) error {
		for i,v := range c._items {
			if v.name == item.name {
				c._items = append(c._items[:i], c._items[i+1:])
			}
		}
		c._items = append(c._items, item)
        retrun c.save(correlationId)
    }
}

extends MemoryPersistence implements IConfigurable

func NewFilePersistence

func NewFilePersistence(prototype reflect.Type, persister *JsonFilePersister) *FilePersistence

Creates a new instance of the persistence.

  • persister (optional) a persister component that loads and saves data from/to flat file.

Return *FilePersistence Pointer on new FilePersistence instance

func (*FilePersistence) Configure

func (c *FilePersistence) Configure(conf *config.ConfigParams)

Configures component by passing configuration parameters.

  • config configuration parameters to be set.

type IFilteredPageReader

type IFilteredPageReader interface {

	// Gets a page of data items using filter
	// Parameters
	//   - correlation_id
	//   transaction id to trace execution through call chain.
	//   - filter  data.FilterParams
	//   filter parameters
	//   - paging data.PagingParams
	//   paging parameters
	//   - sort data.SortParams
	//   sort parameters
	// Retrun  interface{}, error
	// list of items or error.
	GetPageByFilter(correlation_id string, filter *data.FilterParams, paging *data.PagingParams, sort *data.SortParams) (page interface{}, err error)
}

IFilteredPageReader is interface for data processing components that can retrieve a page of data items by a filter.

type IFilteredReader

type IFilteredReader interface {

	// Gets a list of data items using filter
	// Parameters:
	// 	  - correlation_id string
	//	  transaction id to trace execution through call chain.
	// 	  - filter data.FilterParams
	//    filter parameters
	// 	  - sort  data.SortParams
	//	  sort parameters
	// Returns []interfcace{}, error
	// receives list of items or error.
	GetListByFilter(correlation_id string, filter *data.FilterParams, sort *data.SortParams) (items []interface{}, err error)
}

Interface for data processing components that can retrieve a list of data items by filter.

type IGetter

type IGetter interface {

	//  Gets a data items by its unique id.
	//  Parameters:
	//    - correlation_id    (optional) transaction id to trace execution through call chain.
	//    - id                an id of item to be retrieved.
	//  Return interface{}, error
	// item or error
	GetOneById(correlation_id string, id interface{}) (item interface{}, err error)
}
Interface for data processing components that can get data items.

<T extends IIdentifiable<K>, K>

type ILoader

type ILoader interface {

	// Loads data items.
	// Parameters:
	//   - correlation_id string
	//   transaction id to trace execution through call chain.
	// Retruns []interface{}, error
	// a list of data items or error.
	Load(correlation_id string) (items []interface{}, err error)
}

Interface for data processing components that load data items.

type IPartialUpdater

type IPartialUpdater interface {

	// Updates only few selected fields in a data item.
	// Parameters:
	//   - correlation_id string
	//   transaction id to trace execution through call chain.
	//   - id interface{}
	//   an id of data item to be updated.
	//   - data data.AnyValueMap
	//   a map with fields to be updated.
	// Returns interface{}, error
	// updated item or error.
	UpdatePartially(correlation_id string, id interface{}, data *data.AnyValueMap) (item interface{}, err error)
}
Interface for data processing components to update data items partially.

<T, K>

type IQuerablePageReader

type IQuerablePageReader interface {

	//  Gets a page of data items using a query string.
	//  Parameters:
	//   - correlation_id string
	//   transaction id to trace execution through call chain.
	//   - query string
	//    a query string
	//   - paging data.PagingParams
	//    paging parameters
	//   - sort  data.SortParams
	//    sort parameters
	// Returns interface{}, error
	// receives list of items or error.
	GetPageByQuery(correlation_id string, query string, paging *data.PagingParams, sort *data.SortParams) (page interface{}, err error)
}

Interface for data processing components that can query a page of data items.

type IQuerableReader

type IQuerableReader interface {

	//  Gets a list of data items using a query string.
	//  Prameters:
	//   - correlation_id  string
	//   transaction id to trace execution through call chain.
	//   - query string
	//   a query string
	//   - sort data.SortParams
	//   sort parameters
	// Returns []interface{}, error
	// list of items or error.
	GetListByQuery(correlation_id string, query string, sort *data.SortParams) (items []interface{}, err error)
}

Interface for data processing components that can query a list of data items.

type ISaver

type ISaver interface {

	// Saves given data items.
	// Parameters:
	//  - correlation_id string
	//  transaction id to trace execution through call chain.
	//  - items []interface{}
	//  a list of items to save.
	// Retuirns error or nil for success.
	Save(correlation_id string, items []interface{}) error
}

Interface for data processing components that save data items.

type ISetter

type ISetter interface {

	// Sets a data item. If the data item exists it updates it,
	// otherwise it create a new data item.
	// Parameters:
	//   - correlation_id string
	//   transaction id to trace execution through call chain.
	//   - item  interface{}
	//   a item to be set.
	// Retruns interface{}, error
	// updated item or error.
	Set(correlation_id string, item interface{}) (value interface{}, err error)
}

Interface for data processing components that can set (create or update) data items.

type IWriter

type IWriter interface {

	// Creates a data item.
	// Parameters:
	//   - correlation_id string
	//   transaction id to trace execution through call chain.
	//   - item interface{}
	//   an item to be created.
	// Returns  interface{}, error
	// created item or error.
	Create(correlation_id string, item interface{}) (value interface{}, err error)

	// Updates a data item.
	// Parameters:
	// 	  - correlation_id  string
	//    transaction id to trace execution through call chain.
	// 	  - item interface{}
	//    an item to be updated.
	// Returns: interface{}, error
	// updated item or error.
	Update(correlation_id string, item interface{}) (value interface{}, err error)

	//  Deleted a data item by it's unique id.
	//	Parameters:
	//    - correlation_id string
	//	  transaction id to trace execution through call chain.
	//    - id interface{}
	//	  an id of the item to be deleted
	//  Returns: interface{}, error
	//  deleted item or error.
	DeleteById(correlation_id string, id interface{}) (value interface{}, err error)
}

Interface for data processing components that can create, update and delete data items.

type IdentifiableFilePersistence

type IdentifiableFilePersistence struct {
	IdentifiableMemoryPersistence
	Persister *JsonFilePersister
}

Abstract persistence component that stores data in flat files and implements a number of CRUD operations over data items with unique ids. The data items must implement

IIdentifiable interface

In basic scenarios child classes shall only override GetPageByFilter, GetListByFilter or DeleteByFilter operations with specific filter function. All other operations can be used out of the box.

In complex scenarios child classes can implement additional operations by accessing cached items via IdentifiableFilePersistence._items property and calling Save method on updates.

See JsonFilePersister See MemoryPersistence

Configuration parameters

  • path: path to the file where data is stored

  • options:

  • max_page_size: Maximum number of items returned in a single page (default: 100)

    References

- *:logger:*:*:1.0 (optional) ILogger components to pass log messages

Examples

type MyFilePersistence  struct {
	IdentifiableFilePersistence
}
    func NewMyFilePersistence(path string)(mfp *MyFilePersistence) {
		mfp = MyFilePersistence{}
		prototype := reflect.TypeOf(MyData{})
		mfp.IdentifiableFilePersistence = *NewJsonPersister(prototype,path)
		return mfp
    }

    func composeFilter(filter cdata.FilterParams)(func (item interface{})bool) {
		if filter == nil {
			filter = NewFilterParams()
		}
        name := filter.GetAsNullableString("name");
        return func (item interface) bool {
            dummy, ok := item.(MyData)
			if *name != "" && ok && dummy.Name != *name {
				return false
			}
            return true
        }
    }

    func (c *MyFilePersistence ) GetPageByFilter(correlationId string, filter FilterParams, paging PagingParams)(page cdata.MyDataPage, err error){
		tempPage, err := c.GetPageByFilter(correlationId, composeFilter(filter), paging, nil, nil)
		dataLen := int64(len(tempPage.Data))
		data := make([]MyData, dataLen)
		for i, v := range tempPage.Data {
			data[i] = v.(MyData)
		}
		page = *NewMyDataPage(&dataLen, data)
		return page, err
    }

    persistence := NewMyFilePersistence("./data/data.json")

	_, errc := persistence.Create("123", { Id: "1", Name: "ABC" })
	if (errc != nil) {
		panic()
	}
    page, errg := persistence.GetPageByFilter("123", NewFilterParamsFromTuples("Name", "ABC"), nil)
    if errg != nil {
		panic("Error")
	}
    fmt.Println(page.Data)         // Result: { Id: "1", Name: "ABC" )
    persistence.DeleteById("123", "1")

func NewIdentifiableFilePersistence

func NewIdentifiableFilePersistence(prototype reflect.Type, persister *JsonFilePersister) *IdentifiableFilePersistence

Creates a new instance of the persistence. Parameters:

  • prototype reflect.Type type of contained data
  • persister (optional) a persister component that loads and saves data from/to flat file.

Return *IdentifiableFilePersistence pointer on new IdentifiableFilePersistence

func (*IdentifiableFilePersistence) Configure

func (c *IdentifiableFilePersistence) Configure(config *config.ConfigParams)

Configures component by passing configuration parameters. Parameters:

  • config configuration parameters to be set.

type IdentifiableMemoryPersistence

type IdentifiableMemoryPersistence struct {
	MemoryPersistence
}

Abstract persistence component that stores data in memory and implements a number of CRUD operations over data items with unique ids. The data items must have Id field.

In basic scenarios child structs shall only override GetPageByFilter, GetListByFilter or DeleteByFilter operations with specific filter function. All other operations can be used out of the box.

In complex scenarios child structes can implement additional operations by accessing cached items via c.Items property and calling Save method on updates.

See MemoryPersistence

Configuration parameters

- options:

  • max_page_size: Maximum number of items returned in a single page (default: 100)

    References

- *:logger:*:*:1.0 (optional) ILogger components to pass log messages

Examples

 type MyMemoryPersistence struct{
 	IdentifiableMemoryPersistence
 }
     func composeFilter(filter: FilterParams) (func (item interface{}) bool ) {
         if filter == nil {
 			filter = NewFilterParams()
 		}
         name := filter.getAsNullableString("Name");
         return func(item interface{}) bool {
 			dummy, ok := item.(MyData)
             if (*name != "" && ok && item.Name != *name)
                 return false;
             return true;
         };
     }

     func (mmp * MyMemoryPersistence) GetPageByFilter(correlationId string, filter FilterParams, paging PagingParams) (page DataPage, err error) {
         tempPage, err := c.GetPageByFilter(correlationId, composeFilter(filter), paging, nil, nil)
 		dataLen := int64(len(tempPage.Data))
 		data := make([]MyData, dataLen)
 		for i, v := range tempPage.Data {
 			data[i] = v.(MyData)
 		}
 		page = *NewMyDataPage(&dataLen, data)
 		return page, err}

     persistence := NewMyMemoryPersistence();

 	item, err := persistence.Create("123", { Id: "1", Name: "ABC" })
 	...
 	page, err := persistence.GetPageByFilter("123", NewFilterParamsFromTuples("Name", "ABC"), nil)
 	if err != nil {
 		panic("Error can't get data")
 	}
     fmt.Prnitln(page.data)         // Result: { Id: "1", Name: "ABC" }
 	item, err := persistence.DeleteById("123", "1")
 	...

extends MemoryPersistence implements IConfigurable, IWriter, IGetter, ISetter

func NewIdentifiableMemoryPersistence

func NewIdentifiableMemoryPersistence(prototype reflect.Type) (c *IdentifiableMemoryPersistence)

Creates a new empty instance of the persistence. Parameters:

  • prototype reflect.Type data type of contains items

Return * IdentifiableMemoryPersistence created empty IdentifiableMemoryPersistence

func (*IdentifiableMemoryPersistence) Configure

func (c *IdentifiableMemoryPersistence) Configure(config *config.ConfigParams)

Configures component by passing configuration parameters. Parameters:

  • config *config.ConfigParams configuration parameters to be set.

func (*IdentifiableMemoryPersistence) Create

func (c *IdentifiableMemoryPersistence) Create(correlationId string, item interface{}) (result interface{}, err error)

Creates a data item. Returns:

  • correlation_id string (optional) transaction id to trace execution through call chain.
  • item string an item to be created.

Returns: interface{}, error created item or error.

func (*IdentifiableMemoryPersistence) DeleteById

func (c *IdentifiableMemoryPersistence) DeleteById(correlationId string, id interface{}) (result interface{}, err error)

Deleted a data item by it's unique id. Parameters:

  • correlation_id string (optional) transaction id to trace execution through call chain.
  • id interface{} an id of the item to be deleted

Retruns: interface{}, error deleted item or error.

func (*IdentifiableMemoryPersistence) DeleteByIds

func (c *IdentifiableMemoryPersistence) DeleteByIds(correlationId string, ids []interface{}) (err error)

Deletes multiple data items by their unique ids. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.
  • ids []interface{} ids of data items to be deleted.

Returns: error error or null for success.

func (*IdentifiableMemoryPersistence) GetIndexById added in v1.0.6

func (c *IdentifiableMemoryPersistence) GetIndexById(id interface{}) int

Get index by "Id" field return index number

func (*IdentifiableMemoryPersistence) GetListByIds

func (c *IdentifiableMemoryPersistence) GetListByIds(correlationId string, ids []interface{}) (result []interface{}, err error)

Gets a list of data items retrieved by given unique ids. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.
  • ids []interface{} ids of data items to be retrieved

Returns []interface{}, error data list or error.

func (*IdentifiableMemoryPersistence) GetOneById

func (c *IdentifiableMemoryPersistence) GetOneById(correlationId string, id interface{}) (result interface{}, err error)

Gets a data item by its unique id. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.
  • id interface{} an id of data item to be retrieved.

Returns: interface{}, error data item or error.

func (*IdentifiableMemoryPersistence) Set

func (c *IdentifiableMemoryPersistence) Set(correlationId string, item interface{}) (result interface{}, err error)

Sets a data item. If the data item exists it updates it, otherwise it create a new data item. Parameters:

  • correlation_id string (optional) transaction id to trace execution through call chain.
  • item interface{} a item to be set.

Returns: interface{}, error updated item or error.

func (*IdentifiableMemoryPersistence) Update

func (c *IdentifiableMemoryPersistence) Update(correlationId string, item interface{}) (result interface{}, err error)

Updates a data item. Parameters:

  • correlation_id string (optional) transaction id to trace execution through call chain.
  • item interface{} an item to be updated.

Returns: interface{}, error updated item or error.

func (*IdentifiableMemoryPersistence) UpdatePartially

func (c *IdentifiableMemoryPersistence) UpdatePartially(correlationId string, id interface{}, data *cdata.AnyValueMap) (result interface{}, err error)

Updates only few selectFuncected fields in a data item. Parameters:

  • correlation_id string (optional) transaction id to trace execution through call chain.
  • id interface{} an id of data item to be updated.
  • data cdata.AnyValueMap a map with fields to be updated.

Returns: interface{}, error updated item or error.

type JsonFilePersister

type JsonFilePersister struct {
	Prototype reflect.Type
	// contains filtered or unexported fields
}

Persistence component that loads and saves data from/to flat file.

It is used by FilePersistence, but can be useful on its own.

Configuration parameters

 - path:          path to the file where data is stored

Example

 persister := NewJsonFilePersister(reflect.TypeOf(MyData{}), "./data/data.json");

 err_sav := persister.Save("123", ["A", "B", "C"])
 if err_sav == nil {
 	items, err_lod := persister.Load("123")
 	if err_lod == nil {
 		fmt.Println(items);// Result: ["A", "B", "C"]
 	}

implements ILoader, ISaver, IConfigurable

func NewJsonFilePersister

func NewJsonFilePersister(prototype reflect.Type, path string) *JsonFilePersister

Creates a new instance of the persistence. Parameters:

  • path string (optional) a path to the file where data is stored.

func (*JsonFilePersister) Configure

func (c *JsonFilePersister) Configure(config *config.ConfigParams)

Configures component by passing configuration parameters. Parameters:

  • config config.ConfigParams parameters to be set.

func (*JsonFilePersister) Load

func (c *JsonFilePersister) Load(correlation_id string) (data []interface{}, err error)

Loads data items from external JSON file. Parameters:

  • correlation_id string transaction id to trace execution through call chain.

Returns []interface{}, error loaded items or error.

func (*JsonFilePersister) Path

func (c *JsonFilePersister) Path() string

Gets the file path where data is stored. Returns the file path where data is stored.

func (*JsonFilePersister) Save

func (c *JsonFilePersister) Save(correlationId string, items []interface{}) error

Saves given data items to external JSON file. Parameters:

  • correlation_id string transaction id to trace execution through call chain.
  • items []interface[] list of data items to save Retruns error error or nil for success.

func (*JsonFilePersister) SetPath

func (c *JsonFilePersister) SetPath(value string)

Sets the file path where data is stored. Parameters:

  • value string the file path where data is stored.

type MemoryPersistence

type MemoryPersistence struct {
	Logger *log.CompositeLogger
	Items  []interface{}
	Loader ILoader
	Saver  ISaver

	Prototype   reflect.Type
	Lock        sync.RWMutex
	MaxPageSize int
	// contains filtered or unexported fields
}

Abstract persistence component that stores data in memory.

This is the most basic persistence component that is only able to store data items of any type. Specific CRUD operations over the data items must be implemented in child struct by accessing Items property and calling Save method.

The component supports loading and saving items from another data source. That allows to use it as a base struct for file and other types of persistence components that cache all data in memory.

References

- *:logger:*:*:1.0 ILogger components to pass log messages

Example

type MyMemoryPersistence struct {
    MemoryPersistence

}
 func (c * MyMemoryPersistence) GetByName(correlationId string, name string)(item interface{}, err error) {
    for _, v := range c.Items {
        if v.name == name {
            item = v
            break
        }
    }
    return item, nil
});

func (c * MyMemoryPersistence) Set(correlatonId: string, item: MyData, callback: (err) => void): void {
    c.Items = append(c.Items, item);
    c.Save(correlationId);
}

persistence := NewMyMemoryPersistence();
err := persistence.Set("123", MyData{ name: "ABC" })
item, err := persistence.GetByName("123", "ABC")
fmt.Println(item)   // Result: { name: "ABC" }

implements IReferenceable, IOpenable, ICleanable

func NewMemoryPersistence

func NewMemoryPersistence(prototype reflect.Type) *MemoryPersistence

Creates a new instance of the MemoryPersistence Parameters:

  • prototype reflect.Type type of contained data

Return *MemoryPersistence a MemoryPersistence

func (*MemoryPersistence) Clear

func (c *MemoryPersistence) Clear(correlationId string) error

Clears component state. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain. Returns error or null no errors occured.

func (*MemoryPersistence) Close

func (c *MemoryPersistence) Close(correlationId string) error

Closes component and frees used resources. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.

Retruns: error or nil if no errors occured.

func (*MemoryPersistence) Create added in v1.0.5

func (c *MemoryPersistence) Create(correlationId string, item interface{}) (result interface{}, err error)

Creates a data item. Returns:

  • correlation_id string (optional) transaction id to trace execution through call chain.
  • item string an item to be created.

Returns: interface{}, error created item or error.

func (*MemoryPersistence) DeleteByFilter added in v1.0.5

func (c *MemoryPersistence) DeleteByFilter(correlationId string, filterFunc func(interface{}) bool) (err error)

Deletes data items that match to a given filter. this method shall be called by a func (c* IdentifiableMemoryPersistence) DeleteByFilter method from child struct that receives FilterParams and converts them into a filter function. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.
  • filter filter func(interface{}) bool (optional) a filter function to filter items.

Retruns: error error or nil for success.

func (*MemoryPersistence) GetCountByFilter added in v1.0.5

func (c *MemoryPersistence) GetCountByFilter(correlationId string, filterFunc func(interface{}) bool) (count int64, err error)

Gets a count of data items retrieved by a given filter. this method shall be called by a func (imp* IdentifiableMemoryPersistence) getCountByFilter method from child struct that receives FilterParams and converts them into a filter function. Parameters:

  • correlationId string transaction id to trace execution through call chain.
  • filter func(interface{}) bool (optional) a filter function to filter items

Return int, error data count or error.

func (*MemoryPersistence) GetListByFilter added in v1.0.5

func (c *MemoryPersistence) GetListByFilter(correlationId string, filterFunc func(interface{}) bool,
	sortFunc func(a, b interface{}) bool, selectFunc func(in interface{}) (out interface{})) (results []interface{}, err error)

Gets a list of data items retrieved by a given filter and sorted according to sort parameters. This method shall be called by a func (c * IdentifiableMemoryPersistence) GetListByFilter method from child struct that receives FilterParams and converts them into a filter function. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.
  • filter func(interface{}) bool (optional) a filter function to filter items
  • sortFunc func(a, b interface{}) bool (optional) sorting compare function func Less (a, b interface{}) bool see sort.Interface Less function
  • selectFunc func(in interface{}) (out interface{}) (optional) projection parameters

Returns []interface{}, error array of items and error

func (*MemoryPersistence) GetOneRandom added in v1.0.5

func (c *MemoryPersistence) GetOneRandom(correlationId string, filterFunc func(interface{}) bool) (result interface{}, err error)

Gets a random item from items that match to a given filter. This method shall be called by a func (c* IdentifiableMemoryPersistence) GetOneRandom method from child type that receives FilterParams and converts them into a filter function. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.
  • filter func(interface{}) bool (optional) a filter function to filter items.

Returns: interface{}, error random item or error.

func (*MemoryPersistence) GetPageByFilter added in v1.0.5

func (c *MemoryPersistence) GetPageByFilter(correlationId string, filterFunc func(interface{}) bool,
	paging *cdata.PagingParams, sortFunc func(a, b interface{}) bool, selectFunc func(in interface{}) (out interface{})) (page *cdata.DataPage, err error)

Gets a page of data items retrieved by a given filter and sorted according to sort parameters. cmethod shall be called by a func (imp* IdentifiableMemoryPersistence) getPageByFilter method from child struct that receives FilterParams and converts them into a filter function. Parameters:

  • correlationId string transaction id to trace execution through call chain.
  • filter func(interface{}) bool (optional) a filter function to filter items
  • paging *cdata.PagingParams (optional) paging parameters
  • sortFunc func(a, b interface{}) bool (optional) sorting compare function func Less (a, b interface{}) bool see sort.Interface Less function
  • selectFunc func(in interface{}) (out interface{})

(optional) projection parameters Return cdata.DataPage, error data page or error.

func (*MemoryPersistence) IsOpen

func (c *MemoryPersistence) IsOpen() bool

Checks if the component is opened. Returns true if the component has been opened and false otherwise.

func (*MemoryPersistence) Open

func (c *MemoryPersistence) Open(correlationId string) error

Opens the component. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.

Returns error or null no errors occured.

func (*MemoryPersistence) Save

func (c *MemoryPersistence) Save(correlationId string) error

Saves items to external data source using configured saver component. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.

Return error or null for success.

func (*MemoryPersistence) SetReferences

func (c *MemoryPersistence) SetReferences(references refer.IReferences)

Sets references to dependent components. Parameters:

  • references refer.IReferences references to locate the component dependencies.

Jump to

Keyboard shortcuts

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