IdentifiablePostgresPersistence<T extends IIdentifiable<K> , K> class
Null safety
Abstract persistence component that stores data in Postgres 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 this.connection_ and this.client_ properties.
Configuration parameters
table
: (optional) Postgres table nameschema
: (optional) Postgres schema nameconnection(s)
:discovery_key
: (optional) a key to retrieve the connection from IDiscoveryhost
: host name or IP addressport
: port number (default: 5432)uri
: resource URI or connection string with all parameters in it
credential(s)
:store_key
: (optional) a key to retrieve the credentials from ICredentialStoreusername
: (optional) user namepassword
: (optional) user password
options
:connect_timeout
: (optional) number of milliseconds to wait before timing out when connecting a new client (default: 10000)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) ILogger components to pass log messages
- *:discovery:::1.0 (optional) IDiscovery services
- *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
Example
class MyPostgresPersistence extends IdentifiablePostgresPersistence<MyData, String> {
MyPostgresPersistence() : super('mydata', null);
@override
void defineSchema_() {
this.clearSchema();
this.ensureSchema_('CREATE TABLE ' +
this.tableName_! +
' (id TEXT PRIMARY KEY, key TEXT, content TEXT)');
this.ensureIndex_(this.tableName_! + '_key', {'key': 1}, {'unique': true});
}
Future<DataPage<Dummy>> getPageByFilter(
String? correlationId, FilterParams? filter, PagingParams? paging) {
filter = filter ?? FilterParams();
var key = filter.getAsNullableString('key');
var filterCondition = "";
if (key != null) filterCondition += "key='" + key + "'";
return super
.getPageByFilter_(correlationId, filterCondition, paging, null, null);
}
}
var persistence = MyPostgresPersistence();
persistence
.configure(ConfigParams.fromTuples(["host", "localhost", "port", 5432]));
await persistence.open(null);
var item = await persistence.create(null, MyData());
var page = await persistence.getPageByFilter(
null, FilterParams.fromTuples(["key", "ABC"]), null);
print(page.data);
var deleted = await persistence.deleteById(null, '1');
- Inheritance
- Object
- PostgresPersistence<
T> - IdentifiablePostgresPersistence
- Implemented types
- Implementers
Constructors
- IdentifiablePostgresPersistence(String? tableName, String? schemaName)
- Creates a new instance of the persistence component. [...]
Properties
- autoGenerateId_ ↔ bool
-
read / write
- client_ ↔ PostgreSQLConnection?
-
read / write, inherited
- connection_ ↔ PostgresConnection?
-
read / write, inherited
- databaseName_ ↔ String?
-
read / write, inherited
- dependencyResolver_ ↔ DependencyResolver
-
read / write, inherited
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- logger_ ↔ CompositeLogger
-
read / write, inherited
- maxPageSize_ ↔ int
-
read / write, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
- schemaName_ ↔ String?
-
read / write, inherited
- tableName_ ↔ String?
-
read / write, inherited
Methods
-
clear(
String? correlationId) → Future -
Clears component state. [...]
inherited
-
clearSchema(
) → void -
Clears all auto-created objects
inherited
-
close(
String? correlationId) → Future -
Closes component and frees used resources. [...]
inherited
-
configure(
ConfigParams config) → void -
Configures component by passing configuration parameters. [...]
inherited
-
convertFromPublic_(
dynamic value) → dynamic -
Convert object value from public to internal format. [...]
inherited
-
convertFromPublicPartial_(
dynamic value) → dynamic - Converts the given object from the public partial format. [...]
-
convertToPublic_(
dynamic value) → dynamic -
Converts object value from internal to public format. [...]
inherited
-
create(
String? correlationId, T? item) → Future< T?> -
Creates a data item. [...]
override
-
createSchema_(
String? correlationId) → Future< void> -
inherited
-
defineSchema_(
) → void -
Defines database schema via auto create objects or convenience methods.
inherited
-
deleteByFilter_(
String? correlationId, String? filter) → Future< void> -
Deletes data items that match to a given filter. [...]
inherited
-
deleteById(
String? correlationId, K? id) → Future< T?> -
Deleted a data item by it's unique id. [...]
override
-
deleteByIds(
String? correlationId, List< K> ids) → Future<void> - Deletes multiple data items by their unique ids. [...]
-
ensureIndex_(
String name, Map keys, Map? options) → void -
Adds index definition to create it on opening [...]
inherited
-
ensureSchema_(
String schemaStatement) → void -
Adds a statement to schema definition [...]
inherited
-
generateColumns_(
dynamic values) → String -
Generates a list of column names to use in SQL statements like: "column1,column2,column3" [...]
inherited
-
generateParameters_(
dynamic values) → String -
Generates a list of value parameters to use in SQL statements like: "@1,@2,@3" [...]
inherited
-
generateSetParameters_(
Map values) → String -
Generates a list of column sets to use in UPDATE statements like: column1=@1,column2=@2 [...]
inherited
-
generateValues_(
dynamic values) → Map< String, dynamic> -
Generates a list of column parameters [...]
inherited
-
getCountByFilter_(
String? correlationId, String? filter) → Future< int> -
Gets a number of data items retrieved by a given filter. [...]
inherited
-
getListByFilter_(
String? correlationId, String? filter, String? sort, String? select) → Future< List< T> > -
Gets a list of data items retrieved by a given filter and sorted according to sort parameters. [...]
inherited
-
getListByIds(
String? correlationId, List< K> ids) → Future<List< T> > - Gets a list of data items retrieved by given unique ids. [...]
-
getOneById(
String? correlationId, K id) → Future< T?> -
Gets a data item by its unique id. [...]
override
-
getOneRandom_(
String? correlationId, String? filter) → Future< T?> -
inherited
-
getPageByFilter_(
String? correlationId, String? filter, PagingParams? paging, String? sort, String? select) → Future< DataPage< T> > -
Gets a page of data items retrieved by a given filter and sorted according to sort parameters. [...]
inherited
-
isOpen(
) → bool -
Checks if the component is opened. [...]
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
open(
String? correlationId) → Future -
Opens the component. [...]
inherited
-
quotedTableName_(
) → String -
inherited
-
quoteIdentifier_(
String? value) → String -
inherited
-
set(
String? correlationId, T? item) → Future< T?> -
Sets a data item. If the data item exists it updates it,
otherwise it create a new data item. [...]
override
-
setReferences(
IReferences references) → void -
Sets references to dependent components. [...]
inherited
-
toString(
) → String -
A string representation of this object. [...]
inherited
-
unsetReferences(
) → void -
Unsets (clears) previously set references to dependent components.
inherited
-
update(
String? correlationId, T? item) → Future< T?> -
Updates a data item. [...]
override
-
updatePartially(
String? correlationId, K? id, AnyValueMap? data) → Future< T?> - Updates only few selected fields in a data item. [...]
Operators
-
operator ==(
Object other) → bool -
The equality operator. [...]
inherited