Documentation
¶
Index ¶
- type ISqlitePersistenceOverrides
- type IdentifiableJsonSqlitePersistence
- func (c *IdentifiableJsonSqlitePersistence) ConvertFromPublic(value interface{}) interface{}
- func (c *IdentifiableJsonSqlitePersistence) ConvertFromPublicPartial(value interface{}) interface{}
- func (c *IdentifiableJsonSqlitePersistence) ConvertToPublic(rows *sql.Rows) interface{}
- func (c *IdentifiableJsonSqlitePersistence) EnsureTable(idType string, dataType string)
- func (c *IdentifiableJsonSqlitePersistence) UpdatePartially(correlationId string, id interface{}, data *cdata.AnyValueMap) (result interface{}, err error)
- type IdentifiableSqlitePersistence
- func (c *IdentifiableSqlitePersistence) Create(correlationId string, item interface{}) (result interface{}, err error)
- func (c *IdentifiableSqlitePersistence) DeleteById(correlationId string, id interface{}) (result interface{}, err error)
- func (c *IdentifiableSqlitePersistence) DeleteByIds(correlationId string, ids []interface{}) error
- func (c *IdentifiableSqlitePersistence) GetListByIds(correlationId string, ids []interface{}) (items []interface{}, err error)
- func (c *IdentifiableSqlitePersistence) GetOneById(correlationId string, id interface{}) (item interface{}, err error)
- func (c *IdentifiableSqlitePersistence) Set(correlationId string, item interface{}) (result interface{}, err error)
- func (c *IdentifiableSqlitePersistence) Update(correlationId string, item interface{}) (result interface{}, err error)
- func (c *IdentifiableSqlitePersistence) UpdatePartially(correlationId string, id interface{}, data *cdata.AnyValueMap) (result interface{}, err error)
- type SqlitePersistence
- func (c *SqlitePersistence) Clear(correlationId string) error
- func (c *SqlitePersistence) ClearSchema()
- func (c *SqlitePersistence) Close(correlationId string) (err error)
- func (c *SqlitePersistence) Configure(config *cconf.ConfigParams)
- func (c *SqlitePersistence) ConvertFromPublic(value interface{}) interface{}
- func (c *SqlitePersistence) ConvertFromPublicPartial(value interface{}) interface{}
- func (c *SqlitePersistence) ConvertToPublic(rows *sql.Rows) interface{}
- func (c *SqlitePersistence) Create(correlationId string, item interface{}) (result interface{}, err error)
- func (c *SqlitePersistence) CreateSchema(correlationId string) (err error)
- func (c *SqlitePersistence) DefineSchema()
- func (c *SqlitePersistence) DeleteByFilter(correlationId string, filter string) (err error)
- func (c *SqlitePersistence) DereferenceObject(docPointer reflect.Value) interface{}
- func (c *SqlitePersistence) EnsureIndex(name string, keys map[string]string, options map[string]string)
- func (c *SqlitePersistence) EnsureSchema(schemaStatement string)
- func (c *SqlitePersistence) GenerateColumns(values interface{}) string
- func (c *SqlitePersistence) GenerateParameters(values interface{}) string
- func (c *SqlitePersistence) GenerateSetParameters(values interface{}) (params string, columns string)
- func (c *SqlitePersistence) GenerateValues(columns string, values interface{}) []interface{}
- func (c *SqlitePersistence) GetCountByFilter(correlationId string, filter interface{}) (count int64, err error)
- func (c *SqlitePersistence) GetListByFilter(correlationId string, filter interface{}, sort interface{}, sel interface{}) (items []interface{}, err error)
- func (c *SqlitePersistence) GetOneRandom(correlationId string, filter interface{}) (item interface{}, err error)
- func (c *SqlitePersistence) GetPageByFilter(correlationId string, filter interface{}, paging *cdata.PagingParams, ...) (page *cdata.DataPage, err error)
- func (c *SqlitePersistence) IsOpen() bool
- func (c *SqlitePersistence) NewObjectByPrototype() reflect.Value
- func (c *SqlitePersistence) Open(correlationId string) (err error)
- func (c *SqlitePersistence) QuoteIdentifier(value string) string
- func (c *SqlitePersistence) SetReferences(references cref.IReferences)
- func (c *SqlitePersistence) UnsetReferences()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ISqlitePersistenceOverrides ¶ added in v1.2.0
type IdentifiableJsonSqlitePersistence ¶
type IdentifiableJsonSqlitePersistence struct {
IdentifiableSqlitePersistence
}
### Configuration parameters ###
- collection: (optional) SQLite collection name - connection(s):
- discovery_key: (optional) a key to retrieve the connection from [[https://rawgit.com/pip-services-node/pip-services3-components-node/master/doc/api/interfaces/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 [[https://rawgit.com/pip-services-node/pip-services3-components-node/master/doc/api/interfaces/auth.icredentialstore.html ICredentialStore]]
- username: (optional) user name
- password: (optional) user password
- options:
- connect_timeout: (optional) number of milliseconds to wait before timing out when connecting a new client (default: 0)
- idle_timeout: (optional) number of milliseconds a client must sit idle in the pool and not be checked out (default: 10000)
- max_pool_size: (optional) maximum number of clients the pool should contain (default: 10)
### References ###
- \*:logger:\*:\*:1.0 (optional) [[https://rawgit.com/pip-services-node/pip-services3-components-node/master/doc/api/interfaces/log.ilogger.html ILogger]] components to pass log messages components to pass log messages - \*:discovery:\*:\*:1.0 (optional) [[https://rawgit.com/pip-services-node/pip-services3-components-node/master/doc/api/interfaces/connect.idiscovery.html IDiscovery]] services - \*:credential-store:\*:\*:1.0 (optional) Credential stores to resolve credentials
### Example ###
type MySqlitePersistence struct { IdentifiableSqliteJsonPersistence }
func NewMySqlitePersistence() * MySqlitePersistence { return &MySqlitePersistence{ IdentifiableSqliteJsonPersistence: NewIdentifiableSqliteJsonPersistence("mydata") } func (c*MySqlitePersistence)composeFilter(filter *cdata.FilterParams) interface{} { if filter == nil { filter = NewFilterParams(); } let criteria = []; let name = filter.getAsNullableString('name'); if (name != null) criteria.push({ name: name }); return criteria.length > 0 ? { $and: criteria } : null; } GetPageByFilter(correlationId: string, filter: FilterParams, paging: PagingParams, callback: (err: any, page: DataPage<MyData>) => void): void { base.getPageByFilter(correlationId, c.composeFilter(filter), paging, null, null, callback); } } let persistence = new MySqlitePersistence(); persistence.configure(ConfigParams.fromTuples( "host", "localhost", "port", 27017 )); persitence.open("123", (err) => { ... }); persistence.create("123", { id: "1", name: "ABC" }, (err, item) => { persistence.getPageByFilter( "123", FilterParams.fromTuples("name", "ABC"), null, (err, page) => { console.log(page.data); // Result: { id: "1", name: "ABC" } persistence.deleteById("123", "1", (err, item) => { ... }); } ) }); */
func InheritIdentifiableJsonSqlitePersistence ¶ added in v1.2.0
func InheritIdentifiableJsonSqlitePersistence(overrides ISqlitePersistenceOverrides, proto reflect.Type, tableName string) *IdentifiableJsonSqlitePersistence
Creates a new instance of the persistence component. - overrides a references to child class that overrides virtual methods - tableName (optional) a table name.
func (*IdentifiableJsonSqlitePersistence) ConvertFromPublic ¶ added in v1.2.0
func (c *IdentifiableJsonSqlitePersistence) ConvertFromPublic(value interface{}) interface{}
Convert object value from public to internal format. - value an object in public format to convert. Returns converted object in internal format.
func (*IdentifiableJsonSqlitePersistence) ConvertFromPublicPartial ¶ added in v1.2.0
func (c *IdentifiableJsonSqlitePersistence) ConvertFromPublicPartial(value interface{}) interface{}
Convert object value from public to internal format. - value an object in public format to convert. Returns converted object in internal format.
func (*IdentifiableJsonSqlitePersistence) ConvertToPublic ¶ added in v1.2.0
func (c *IdentifiableJsonSqlitePersistence) ConvertToPublic(rows *sql.Rows) interface{}
Converts object value from internal to public format. - value an object in internal format to convert. Returns converted object in public format.
func (*IdentifiableJsonSqlitePersistence) EnsureTable ¶
func (c *IdentifiableJsonSqlitePersistence) EnsureTable(idType string, dataType string)
Adds DML statement to automatically create JSON(B) table - idType type of the id column (default: TEXT) - dataType type of the data column (default: JSONB)
func (*IdentifiableJsonSqlitePersistence) UpdatePartially ¶
func (c *IdentifiableJsonSqlitePersistence) UpdatePartially(correlationId string, id interface{}, data *cdata.AnyValueMap) (result interface{}, err error)
Updates only few selected fields in a data item. - 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 callback function that receives updated item or error.
type IdentifiableSqlitePersistence ¶
type IdentifiableSqlitePersistence struct {
*SqlitePersistence
}
Abstract persistence component that stores data in SQLite 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._collection and c._model properties.
### Configuration parameters ###
*
- collection: (optional) SQLite collection name - connection(s):
- discovery_key: (optional) a key to retrieve the connection from [[https://rawgit.com/pip-services-node/pip-services3-components-node/master/doc/api/interfaces/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 [[https://rawgit.com/pip-services-node/pip-services3-components-node/master/doc/api/interfaces/auth.icredentialstore.html ICredentialStore]]
- username: (optional) user name
- password: (optional) user password
- options:
- connect_timeout: (optional) number of milliseconds to wait before timing out when connecting a new client (default: 0)
- idle_timeout: (optional) number of milliseconds a client must sit idle in the pool and not be checked out (default: 10000)
- max_pool_size: (optional) maximum number of clients the pool should contain (default: 10) *
### References ###
*
- \*:logger:\*:\*:1.0 (optional) [[https://rawgit.com/pip-services-node/pip-services3-components-node/master/doc/api/interfaces/log.ilogger.html ILogger]] components to pass log messages components to pass log messages
- \*:discovery:\*:\*:1.0 (optional) [[https://rawgit.com/pip-services-node/pip-services3-components-node/master/doc/api/interfaces/connect.idiscovery.html IDiscovery]] services
- \*:credential-store:\*:\*:1.0 (optional) Credential stores to resolve credentials *
### Example ###
* class MySqlitePersistence extends IdentifiableSqlitePersistence<MyData, string> { * public constructor() { base("mydata", new MyDataSqliteSchema()); } * private composeFilter(filter: FilterParams): any { filter = filter || new FilterParams(); let criteria = []; let name = filter.getAsNullableString('name'); if (name != null) criteria.push({ name: name }); return criteria.length > 0 ? { $and: criteria } : null; } * public getPageByFilter(correlationId: string, filter: FilterParams, paging: PagingParams, callback: (err: any, page: DataPage<MyData>) => void): void { base.getPageByFilter(correlationId, c.composeFilter(filter), paging, null, null, callback); } * } * let persistence = new MySqlitePersistence(); persistence.configure(ConfigParams.fromTuples( "host", "localhost", "port", 27017 )); * persitence.open("123", (err) => { ... }); * persistence.create("123", { id: "1", name: "ABC" }, (err, item) => { persistence.getPageByFilter( "123", FilterParams.fromTuples("name", "ABC"), null, (err, page) => { console.log(page.data); // Result: { id: "1", name: "ABC" } * persistence.deleteById("123", "1", (err, item) => { ... }); } ) });
func InheritIdentifiableSqlitePersistence ¶ added in v1.2.0
func InheritIdentifiableSqlitePersistence(overrides ISqlitePersistenceOverrides, proto reflect.Type, tableName string) *IdentifiableSqlitePersistence
Creates a new instance of the persistence component.
- overrides a references to child class that overrides virtual methods - tableName (optional) a table name.
func (*IdentifiableSqlitePersistence) Create ¶
func (c *IdentifiableSqlitePersistence) Create(correlationId string, item interface{}) (result interface{}, err error)
Creates a data item. - correlation_id (optional) transaction id to trace execution through call chain. - item an item to be created. Returns (optional) created item or error.
func (*IdentifiableSqlitePersistence) DeleteById ¶
func (c *IdentifiableSqlitePersistence) DeleteById(correlationId string, id interface{}) (result interface{}, err error)
Deleted a data item by it's unique id. - correlation_id (optional) transaction id to trace execution through call chain. - id an id of the item to be deleted Returns (optional) deleted item or error.
func (*IdentifiableSqlitePersistence) DeleteByIds ¶
func (c *IdentifiableSqlitePersistence) DeleteByIds(correlationId string, ids []interface{}) error
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 (optional) error or null for success.
func (*IdentifiableSqlitePersistence) GetListByIds ¶
func (c *IdentifiableSqlitePersistence) GetListByIds(correlationId string, ids []interface{}) (items []interface{}, err error)
Gets a list of data items retrieved by given unique ids. - correlationId (optional) transaction id to trace execution through call chain. - ids ids of data items to be retrieved Returns a data list or error.
func (*IdentifiableSqlitePersistence) GetOneById ¶
func (c *IdentifiableSqlitePersistence) GetOneById(correlationId string, id interface{}) (item interface{}, err error)
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 data item or error.
func (*IdentifiableSqlitePersistence) Set ¶
func (c *IdentifiableSqlitePersistence) 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. - correlation_id (optional) transaction id to trace execution through call chain. - item a item to be set. Returns (optional) updated item or error.
func (*IdentifiableSqlitePersistence) Update ¶
func (c *IdentifiableSqlitePersistence) Update(correlationId string, item interface{}) (result interface{}, err error)
Updates a data item. - correlation_id (optional) transaction id to trace execution through call chain. - item an item to be updated. Returns (optional) updated item or error.
func (*IdentifiableSqlitePersistence) UpdatePartially ¶
func (c *IdentifiableSqlitePersistence) UpdatePartially(correlationId string, id interface{}, data *cdata.AnyValueMap) (result interface{}, err error)
Updates only few selected fields in a data item. - 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 updated item or error.
type SqlitePersistence ¶
type SqlitePersistence struct { Overrides ISqlitePersistenceOverrides Prototype reflect.Type //The dependency resolver. DependencyResolver *cref.DependencyResolver //The logger. Logger *clog.CompositeLogger //The SQLite connection component. Connection *conn.SqliteConnection //The SQLite connection pool object. Client *sql.DB //The SQLite database name. DatabaseName string //The SQLite table object. TableName string MaxPageSize int // contains filtered or unexported fields }
func InheritSqlitePersistence ¶ added in v1.2.0
func InheritSqlitePersistence(overrides ISqlitePersistenceOverrides, proto reflect.Type, tableName string) *SqlitePersistence
Creates a new instance of the persistence component. - overrides a references to child class that overrides virtual methods - tableName (optional) a table name.
func (*SqlitePersistence) Clear ¶
func (c *SqlitePersistence) Clear(correlationId string) error
Clears component state. - correlationId (optional) transaction id to trace execution through call chain. - Returns error or nil no errors occured.
func (*SqlitePersistence) ClearSchema ¶
func (c *SqlitePersistence) ClearSchema()
Clears all auto-created objects
func (*SqlitePersistence) Close ¶
func (c *SqlitePersistence) Close(correlationId string) (err error)
Closes component and frees used resources. - correlationId (optional) transaction id to trace execution through call chain. - Returns error or nil no errors occured.
func (*SqlitePersistence) Configure ¶
func (c *SqlitePersistence) Configure(config *cconf.ConfigParams)
Configures component by passing configuration parameters. - config configuration parameters to be set.
func (*SqlitePersistence) ConvertFromPublic ¶
func (c *SqlitePersistence) ConvertFromPublic(value interface{}) interface{}
Convert object value from func (c * SqlitePersistence) to internal format. - value an object in func (c * SqlitePersistence) format to convert. Returns converted object in internal format.
func (*SqlitePersistence) ConvertFromPublicPartial ¶
func (c *SqlitePersistence) ConvertFromPublicPartial(value interface{}) interface{}
Converts the given object from the public partial format. - value the object to convert from the public partial format. Returns the initial object.
func (*SqlitePersistence) ConvertToPublic ¶
func (c *SqlitePersistence) ConvertToPublic(rows *sql.Rows) interface{}
Converts object value from internal to func (c * SqlitePersistence) format. - value an object in internal format to convert. Returns converted object in func (c * SqlitePersistence) format.
func (*SqlitePersistence) Create ¶
func (c *SqlitePersistence) Create(correlationId string, item interface{}) (result interface{}, err error)
Creates a data item. - correlation_id (optional) transaction id to trace execution through call chain. - item an item to be created. - Returns (optional) callback function that receives created item or error.
func (*SqlitePersistence) CreateSchema ¶
func (c *SqlitePersistence) CreateSchema(correlationId string) (err error)
func (*SqlitePersistence) DefineSchema ¶
func (c *SqlitePersistence) DefineSchema()
Defines database schema for the persistence
func (*SqlitePersistence) DeleteByFilter ¶
func (c *SqlitePersistence) DeleteByFilter(correlationId string, filter string) (err error)
Deletes data items that match to a given filter. This method shall be called by a func (c * SqlitePersistence) deleteByFilter method from child class that receives FilterParams and converts them into a filter function. - correlationId (optional) transaction id to trace execution through call chain. - filter (optional) a filter JSON object. - Returns error or nil for success.
func (*SqlitePersistence) DereferenceObject ¶
func (c *SqlitePersistence) DereferenceObject(docPointer reflect.Value) interface{}
func (*SqlitePersistence) EnsureIndex ¶
func (c *SqlitePersistence) EnsureIndex(name string, keys map[string]string, options map[string]string)
Adds index definition to create it on opening - keys index keys (fields) - options index options
func (*SqlitePersistence) EnsureSchema ¶
func (c *SqlitePersistence) EnsureSchema(schemaStatement string)
Adds a statement to schema definition
- schemaStatement a statement to be added to the schema
func (*SqlitePersistence) GenerateColumns ¶
func (c *SqlitePersistence) GenerateColumns(values interface{}) string
Generates a list of column names to use in SQL statements like: "column1,column2,column3" - values an array with column values or a key-value map Returns a generated list of column names
func (*SqlitePersistence) GenerateParameters ¶
func (c *SqlitePersistence) GenerateParameters(values interface{}) string
Generates a list of value parameters to use in SQL statements like: "$1,$2,$3" - values an array with values or a key-value map Returns a generated list of value parameters
func (*SqlitePersistence) GenerateSetParameters ¶
func (c *SqlitePersistence) GenerateSetParameters(values interface{}) (params string, columns string)
Generates a list of column sets to use in UPDATE statements like: column1=$1,column2=$2 - values a key-value map with columns and values Returns a generated list of column sets
func (*SqlitePersistence) GenerateValues ¶
func (c *SqlitePersistence) GenerateValues(columns string, values interface{}) []interface{}
Generates a list of column parameters - values a key-value map with columns and values Returns a generated list of column values
func (*SqlitePersistence) GetCountByFilter ¶
func (c *SqlitePersistence) GetCountByFilter(correlationId string, filter interface{}) (count int64, err error)
Gets a number of data items retrieved by a given filter. This method shall be called by a func (c * SqlitePersistence) getCountByFilter method from child class that receives FilterParams and converts them into a filter function. - correlationId (optional) transaction id to trace execution through call chain. - filter (optional) a filter JSON object - Returns data page or error.
func (*SqlitePersistence) GetListByFilter ¶
func (c *SqlitePersistence) GetListByFilter(correlationId string, filter interface{}, sort interface{}, sel interface{}) (items []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 * SqlitePersistence) getListByFilter method from child class that receives FilterParams and converts them into a filter function. - 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 data list or error.
func (*SqlitePersistence) GetOneRandom ¶
func (c *SqlitePersistence) GetOneRandom(correlationId string, filter interface{}) (item interface{}, err error)
Gets a random item from items that match to a given filter. This method shall be called by a func (c * SqlitePersistence) getOneRandom method from child class that receives FilterParams and converts them into a filter function. - correlationId (optional) transaction id to trace execution through call chain. - filter (optional) a filter JSON object - Returns random item or error.
func (*SqlitePersistence) GetPageByFilter ¶
func (c *SqlitePersistence) GetPageByFilter(correlationId string, filter interface{}, paging *cdata.PagingParams, sort interface{}, sel interface{}) (page *cdata.DataPage, err error)
Gets a page of data items retrieved by a given filter and sorted according to sort parameters. This method shall be called by a func (c * SqlitePersistence) getPageByFilter method from child class that receives FilterParams and converts them into a filter function. - 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 receives a data page or error.
func (*SqlitePersistence) IsOpen ¶
func (c *SqlitePersistence) IsOpen() bool
Checks if the component is opened. Returns true if the component has been opened and false otherwise.
func (*SqlitePersistence) NewObjectByPrototype ¶
func (c *SqlitePersistence) NewObjectByPrototype() reflect.Value
service function for return pointer on new prototype object for unmarshaling
func (*SqlitePersistence) Open ¶
func (c *SqlitePersistence) Open(correlationId string) (err error)
Opens the component. - correlationId (optional) transaction id to trace execution through call chain. - Returns error or nil no errors occured.
func (*SqlitePersistence) QuoteIdentifier ¶
func (c *SqlitePersistence) QuoteIdentifier(value string) string
func (*SqlitePersistence) SetReferences ¶
func (c *SqlitePersistence) SetReferences(references cref.IReferences)
Sets references to dependent components. - references references to locate the component dependencies.
func (*SqlitePersistence) UnsetReferences ¶
func (c *SqlitePersistence) UnsetReferences()
Unsets (clears) previously set references to dependent components.