Documentation ¶
Index ¶
- type CouchbasePersistence
- func (c *CouchbasePersistence) Clear(correlationId string) (err error)
- func (c *CouchbasePersistence) ClearSchema()
- func (c *CouchbasePersistence) Close(correlationId string) (err error)
- func (c *CouchbasePersistence) Configure(config *cconf.ConfigParams)
- func (c *CouchbasePersistence) ConvertFromMap(buf interface{}) interface{}
- func (c *CouchbasePersistence) ConvertFromPublic(item interface{}) interface{}
- func (c *CouchbasePersistence) ConvertFromPublicPartial(value interface{}) interface{}
- func (c *CouchbasePersistence) ConvertToPublic(item interface{}) interface{}
- func (c *CouchbasePersistence) Create(correlationId string, item interface{}) (result interface{}, err error)
- func (c *CouchbasePersistence) CreateSchema(correlationId string) (err error)
- func (c *CouchbasePersistence) DefineSchema()
- func (c *CouchbasePersistence) DeleteByFilter(correlationId string, filter string) (err error)
- func (c *CouchbasePersistence) EnsureIndex(name string, fields []string, deferred bool)
- func (c *CouchbasePersistence) EnsureSchema(schemaStatement schemaStatement)
- func (c *CouchbasePersistence) GenerateBucketId(value interface{}) string
- func (c *CouchbasePersistence) GenerateBucketIds(value []interface{}) []string
- func (c *CouchbasePersistence) GetConvResult(docPointer reflect.Value) interface{}
- func (c *CouchbasePersistence) GetListByFilter(correlationId string, filter string, sort string, sel string) (items []interface{}, err error)
- func (c *CouchbasePersistence) GetOneRandom(correlationId string, filter string) (item interface{}, err error)
- func (c *CouchbasePersistence) GetPageByFilter(correlationId string, filter string, paging *cdata.PagingParams, sort string, ...) (page *cdata.DataPage, err error)
- func (c *CouchbasePersistence) GetProtoPtr() reflect.Value
- func (c *CouchbasePersistence) GetPtrIfNeed(item interface{}) interface{}
- func (c *CouchbasePersistence) IsOpen() bool
- func (c *CouchbasePersistence) Open(correlationId string) (err error)
- func (c *CouchbasePersistence) QuoteIdentifier(value string) string
- func (c *CouchbasePersistence) SetReferences(references cref.IReferences)
- func (c *CouchbasePersistence) UnsetReferences()
- type ICouchbasePersistenceOverrides
- type IdentifiableCouchbasePersistence
- func (c *IdentifiableCouchbasePersistence) Configure(config *cconf.ConfigParams)
- func (c *IdentifiableCouchbasePersistence) Create(correlationId string, item interface{}) (result interface{}, err error)
- func (c *IdentifiableCouchbasePersistence) DeleteById(correlationId string, id interface{}) (item interface{}, err error)
- func (c *IdentifiableCouchbasePersistence) DeleteByIds(correlationId string, ids []interface{}) (err error)
- func (c *IdentifiableCouchbasePersistence) GetListByIds(correlationId string, ids []interface{}) (items []interface{}, err error)
- func (c *IdentifiableCouchbasePersistence) GetOneById(correlationId string, id interface{}) (item interface{}, err error)
- func (c *IdentifiableCouchbasePersistence) Set(correlationId string, item interface{}) (result interface{}, err error)
- func (c *IdentifiableCouchbasePersistence) Update(correlationId string, item interface{}) (result interface{}, err error)
- func (c *IdentifiableCouchbasePersistence) UpdatePartially(correlationId string, id interface{}, data *cdata.AnyValueMap) (item interface{}, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CouchbasePersistence ¶
type CouchbasePersistence struct { Overrides ICouchbasePersistenceOverrides //The dependency resolver. DependencyResolver *crefer.DependencyResolver //The logger. Logger *clog.CompositeLogger //The Couchbase connection component. Connection *connect.CouchbaseConnection //The configuration options. Options *cconf.ConfigParams //The Couchbase cluster object. Cluster *gocb.Cluster //The Couchbase bucket name. BucketName string //The Couchbase bucket object. Bucket *gocb.Bucket // Prototype for convert Prototype reflect.Type CollectionName string MaxPageSize int // contains filtered or unexported fields }
func InheritCouchbasePersistence ¶ added in v1.1.0
func InheritCouchbasePersistence(overrides ICouchbasePersistenceOverrides, proto reflect.Type, bucket string) *CouchbasePersistence
InheritCouchbasePersistence method are creates a new instance of the persistence component. Parameters:
- overrides References to override virtual methods
- bucket a bucket name.
Returns: *CouchbasePersistence pointer on new instance
func (*CouchbasePersistence) Clear ¶
func (c *CouchbasePersistence) Clear(correlationId string) (err error)
Clear method are clears component state.
- correlationId (optional) transaction id to trace execution through call chain.
Returns: error error or nil no errors occured.
func (*CouchbasePersistence) ClearSchema ¶ added in v1.1.0
func (c *CouchbasePersistence) ClearSchema()
Clears all auto-created objects
func (*CouchbasePersistence) Close ¶
func (c *CouchbasePersistence) Close(correlationId string) (err error)
Close method are closes component and frees used resources.
- correlationId (optional) transaction id to trace execution through call chain.
Returns: error error or nil no errors occured.
func (*CouchbasePersistence) Configure ¶
func (c *CouchbasePersistence) Configure(config *cconf.ConfigParams)
Configure method are configures component by passing configuration parameters.
- config configuration parameters to be set.
func (*CouchbasePersistence) ConvertFromMap ¶ added in v1.0.1
func (c *CouchbasePersistence) ConvertFromMap(buf interface{}) interface{}
ConvertFromMap method are converts from map[string]interface{} to object, defined by c.Prototype
func (*CouchbasePersistence) ConvertFromPublic ¶ added in v1.0.1
func (c *CouchbasePersistence) ConvertFromPublic(item interface{}) interface{}
ConvertFromPublic method help convert object (map) from public view by added "_c" field with collection name Parameters:
- item *interface{} item for convert
Returns: *interface{} converted item
func (*CouchbasePersistence) ConvertFromPublicPartial ¶ added in v1.1.0
func (c *CouchbasePersistence) ConvertFromPublicPartial(value interface{}) interface{}
ConvertFromPublicPartial method are converts the given object from the public partial format.
- value the object to convert from the public partial format.
Retruns the initial object.
func (*CouchbasePersistence) ConvertToPublic ¶ added in v1.0.1
func (c *CouchbasePersistence) ConvertToPublic(item interface{}) interface{}
ConvertToPublic method is convert object (map) to public view by exluded "_c" field Parameters:
- item *interface{} item for convert
Returns: *interface{} converted item
func (*CouchbasePersistence) Create ¶ added in v1.0.1
func (c *CouchbasePersistence) Create(correlationId string, item interface{}) (result interface{}, err error)
Create method are creates a data item. Parameters:
- correlation_id (optional) transaction id to trace execution through call chain.
- item an item to be created.
Returns: result interface{}, err error created item or error.
func (*CouchbasePersistence) CreateSchema ¶ added in v1.1.0
func (c *CouchbasePersistence) CreateSchema(correlationId string) (err error)
func (*CouchbasePersistence) DefineSchema ¶ added in v1.1.0
func (c *CouchbasePersistence) DefineSchema()
Defines a database schema for this persistence
func (*CouchbasePersistence) DeleteByFilter ¶ added in v1.0.1
func (c *CouchbasePersistence) DeleteByFilter(correlationId string, filter string) (err error)
DeleteByFilter method are deletes data items that match to a given filter. This method shall be called by a public deleteByFilter method from child class that receives FilterParams and converts them into a filter function. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
- filter (optional) a filter JSON object.
Returns: error error or nil for success.
func (*CouchbasePersistence) EnsureIndex ¶ added in v1.1.0
func (c *CouchbasePersistence) EnsureIndex(name string, fields []string, deferred bool)
Adds index definition to create it on opening
- keys index keys (fields)
- options index options
func (*CouchbasePersistence) EnsureSchema ¶ added in v1.1.0
func (c *CouchbasePersistence) EnsureSchema(schemaStatement schemaStatement)
Adds a statement to schema definition
- schemaStatement a statement to be added to the schema
func (*CouchbasePersistence) GenerateBucketId ¶ added in v1.0.1
func (c *CouchbasePersistence) GenerateBucketId(value interface{}) string
GenerateBucketId method are generates unique id for specific collection in the bucket Parameters:
- value a public unique id.
Retruns a unique bucket id.
func (*CouchbasePersistence) GenerateBucketIds ¶ added in v1.0.1
func (c *CouchbasePersistence) GenerateBucketIds(value []interface{}) []string
Generates a list of unique ids for specific collection in the bucket Parameters:
- value a public unique ids.
Retruns a unique bucket ids.
func (*CouchbasePersistence) GetConvResult ¶ added in v1.0.1
func (c *CouchbasePersistence) GetConvResult(docPointer reflect.Value) interface{}
GetConvResult method are returns properly converted result in interface{} object from pointer in docPointer
func (*CouchbasePersistence) GetListByFilter ¶ added in v1.0.1
func (c *CouchbasePersistence) GetListByFilter(correlationId string, filter string, sort string, sel string) (items []interface{}, err error)
GetListByFilter method are gets a list of data items retrieved by a given filter and sorted according to sort parameters. This method shall be called by a public getListByFilter method from child class that receives FilterParams and converts them into a filter function. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
- filter (optional) a filter JSON object
- paging (optional) paging parameters
- sort (optional) sorting JSON object
- select (optional) projection JSON object
Returns: items []interface{}, err error data list or error.
func (*CouchbasePersistence) GetOneRandom ¶ added in v1.0.1
func (c *CouchbasePersistence) GetOneRandom(correlationId string, filter string) (item interface{}, err error)
GetOneRandom method are gts a random item from items that match to a given filter. This method shall be called by a public getOneRandom method from child class that receives FilterParams and converts them into a filter function. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
- filter (optional) a filter JSON object
Returns: item interface{}, err error a random item or error.
func (*CouchbasePersistence) GetPageByFilter ¶ added in v1.0.1
func (c *CouchbasePersistence) GetPageByFilter(correlationId string, filter string, paging *cdata.PagingParams, sort string, sel string) (page *cdata.DataPage, err error)
GetPageByFilter method are gets a page of data items retrieved by a given filter and sorted according to sort parameters. This method shall be called by a public getPageByFilter method from child class that receives FilterParams and converts them into a filter function. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
- filter (optional) a filter query string after WHERE clause
- paging (optional) paging parameters
- sort (optional) sorting string after ORDER BY clause
- sel (optional) projection string after SELECT clause
Returns: page *cdata.DataPage, err error data page or error.
func (*CouchbasePersistence) GetProtoPtr ¶ added in v1.0.1
func (c *CouchbasePersistence) GetProtoPtr() reflect.Value
GetProtoPtr method are returns pointer on new prototype object for unmarshaling or decode from DB Returns reflect.Value pointer on new empty object
func (*CouchbasePersistence) GetPtrIfNeed ¶ added in v1.0.1
func (c *CouchbasePersistence) GetPtrIfNeed(item interface{}) interface{}
GetPtrIfNeed method are checks c.Prototype if need return pointer or value and returns properly results
func (*CouchbasePersistence) IsOpen ¶
func (c *CouchbasePersistence) IsOpen() bool
IsOpen method are checks if the component is opened. Returns true if the component has been opened and false otherwise.
func (*CouchbasePersistence) Open ¶
func (c *CouchbasePersistence) Open(correlationId string) (err error)
Open method are opens the component.
- correlationId (optional) transaction id to trace execution through call chain.
Return: error error or nil no errors occured.
func (*CouchbasePersistence) QuoteIdentifier ¶ added in v1.1.0
func (c *CouchbasePersistence) QuoteIdentifier(value string) string
func (*CouchbasePersistence) SetReferences ¶
func (c *CouchbasePersistence) SetReferences(references cref.IReferences)
SetReferences method are sets references to dependent components.
- references references to locate the component dependencies.
func (*CouchbasePersistence) UnsetReferences ¶
func (c *CouchbasePersistence) UnsetReferences()
UnsetReferences method is unsets (clears) previously set references to dependent components.
type ICouchbasePersistenceOverrides ¶ added in v1.1.0
type ICouchbasePersistenceOverrides interface { DefineSchema() ConvertFromPublic(item interface{}) interface{} ConvertToPublic(item interface{}) interface{} ConvertFromPublicPartial(item interface{}) interface{} }
type IdentifiableCouchbasePersistence ¶
type IdentifiableCouchbasePersistence struct {
CouchbasePersistence
}
func InheritIdentifiableCouchbasePersistence ¶ added in v1.1.0
func InheritIdentifiableCouchbasePersistence(overrides ICouchbasePersistenceOverrides, proto reflect.Type, bucket string, collection string) *IdentifiableCouchbasePersistence
IdentifiableCouchbasePersistence abstract persistence component that stores data in Couchbase 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 c.Bucket properties.
Configuration parameters:
- bucket: (optional) Couchbase bucket name
- collection: (optional) Couchbase collection name
- connection(s):
- discovery_key: (optional) a key to retrieve the connection from connect.idiscovery.html IDiscovery
- host: host name or IP address
- port: port number (default: 27017)
- uri: resource URI or connection string with all parameters in it
- credential(s):
- store_key: (optional) a key to retrieve the credentials from auth.icredentialstore.html ICredentialStore
- username: (optional) user name
- password: (optional) user password
- options:
- max_pool_size: (optional) maximum connection pool size (default: 2)
- keep_alive: (optional) enable connection keep alive (default: true)
- connect_timeout: (optional) connection timeout in milliseconds (default: 5 sec)
- auto_reconnect: (optional) enable auto reconnection (default: true)
- max_page_size: (optional) maximum page size (default: 100)
- debug: (optional) enable debug output (default: false).
References:
- *:logger:*:*:1.0 (optional) ILogger components to pass log messages components to pass log messages - *:discovery:*:*:1.0 (optional) IDiscovery services - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
Example: type MyCouchbasePersistence struct { *IdentifiableCouchbasePersistence } func NewMyCouchbasePersistence()*MyCouchbasePersistence { c := MyCouchbasePersistence{} c.IdentifiableCouchbasePersistence = NewIdentifiableCouchbasePersistence(reflect.TypeOf(MyData{}), "mybucket", "mycollection") return &c } func (c *MyCouchbasePersistence) GetPageByFilter(correlationId string, filter *cdata.FilterParams, paging *cdata.PagingParams) (page *cbfixture.MyDataPage, err error) { if filter == nil { filter = cdata.NewEmptyFilterParams() } name := filter.GetAsString("name") filterCondition := "" if name != "" { filterCondition += "name='" + name + "'" } tempPage, err := c.IdentifiableCouchbasePersistence.GetPageByFilter(correlationId, filterCondition, paging, "", "") // Convert to MyDataPage dataLen := int64(len(tempPage.Data)) // For full release tempPage and delete this by GC data := make([]cbfixture.MyData, dataLen) for i, v := range tempPage.Data { data[i] = v.(cbfixture.MyData) } page = cbfixture.NewMyDataPage(&dataLen, data) return page, err } persistence := NewMyCouchbasePersistence(); persistence.Configure(ConfigParams.fromTuples( "host", "localhost", "port", 27017, )); persitence.Open("123") ... persistence.Create("123", MyData{ id: "1", name: "ABC" }) ... result, err:= persistence.GetPageByFilter( "123", NewFilterParamsFromTuples("name", "ABC"), nil) fmt.Println(page.data); // Result: { id: "1", name: "ABC" } persistence.DeleteById("123", "1") ...
NewIdentifiableCouchbasePersistence method are creates a new instance of the persistence component. Parameters:
- overrides References to override virtual methods
- proto reflect.Type prototype for properly convert
- bucket string couchbase bucket name
- collection (optional) a collection name.
func (*IdentifiableCouchbasePersistence) Configure ¶
func (c *IdentifiableCouchbasePersistence) Configure(config *cconf.ConfigParams)
Configure method are configures component by passing configuration parameters.
Parameters:
- config configuration parameters to be set.
func (*IdentifiableCouchbasePersistence) Create ¶
func (c *IdentifiableCouchbasePersistence) Create(correlationId string, item interface{}) (result interface{}, err error)
Create method are creates a data item. Parameters:
- correlation_id (optional) transaction id to trace execution through call chain.
- item an item to be created.
Returns: result interface{}, err error created item or error.
func (*IdentifiableCouchbasePersistence) DeleteById ¶
func (c *IdentifiableCouchbasePersistence) DeleteById(correlationId string, id interface{}) (item interface{}, err error)
DeleteById mathod are deleted a data item by its unique id. Parameters:
- correlation_id (optional) transaction id to trace execution through call chain.
- id an id of the item to be deleted
Returns: item interface{}, err error deleted item or error.
func (*IdentifiableCouchbasePersistence) DeleteByIds ¶
func (c *IdentifiableCouchbasePersistence) DeleteByIds(correlationId string, ids []interface{}) (err error)
DeleteByIds methos are deletes multiple data items by their unique ids.
- correlationId (optional) transaction id to trace execution through call chain.
- ids ids of data items to be deleted.
Returns: error error or nil for success.
func (*IdentifiableCouchbasePersistence) GetListByIds ¶
func (c *IdentifiableCouchbasePersistence) GetListByIds(correlationId string, ids []interface{}) (items []interface{}, err error)
GetListByIds method are gets a list of data items retrieved by given unique ids. Parameters:
- correlationId (optional) transaction id to trace execution through call chain.
- ids ids of data items to be retrieved
Returns: items []interface{}, err error a data list or error.
func (*IdentifiableCouchbasePersistence) GetOneById ¶
func (c *IdentifiableCouchbasePersistence) GetOneById(correlationId string, id interface{}) (item interface{}, err error)
GetOneById method are gets a data item by its unique id.
- correlationId (optional) transaction id to trace execution through call chain.
- id an id of data item to be retrieved.
Returns: item interface{}, err error data item or error.
func (*IdentifiableCouchbasePersistence) Set ¶
func (c *IdentifiableCouchbasePersistence) Set(correlationId string, item interface{}) (result interface{}, err error)
Set method are sets a data item. If the data item exists it updates it, otherwise it create a new data item. Parameters:
- correlation_id (optional) transaction id to trace execution through call chain.
- item a item to be set.
- callback (optional) callback function that receives updated item or error.
func (*IdentifiableCouchbasePersistence) Update ¶
func (c *IdentifiableCouchbasePersistence) Update(correlationId string, item interface{}) (result interface{}, err error)
Update method are updates a data item. Parameters:
- correlation_id (optional) transaction id to trace execution through call chain.
- item an item to be updated.
Returns: result interface{}, err error updated item or error.
func (*IdentifiableCouchbasePersistence) UpdatePartially ¶
func (c *IdentifiableCouchbasePersistence) UpdatePartially(correlationId string, id interface{}, data *cdata.AnyValueMap) (item interface{}, err error)
UpdatePartially methos are updates only few selected fields in a data item. Parameters:
- correlation_id (optional) transaction id to trace execution through call chain.
- id an id of data item to be updated.
- data a map with fields to be updated.
Returns: result interface{}, err error updated item or error.