class PostgreSQLBinding(DBBinding):
PostgreSQLBinding class.
| Method | add |
Add a batch notification to the database. |
| Method | add |
Add an originator to the database. |
| Method | backup |
Backup the database to a directory. |
| Method | close |
Close the database. |
| Method | configure |
Configure the PostgreSQLBinding with the provided configuration. |
| Method | count |
Return the number of batch notifications for a resource and notification URI. |
| Method | count |
Return the number of resources in the database. |
| Method | create |
Create the necessary schema and tables if they do not exist. |
| Method | delete |
Delete an identifier from the identifiers DB. |
| Method | delete |
Remnove all stored requests from the database. |
| Method | delete |
Delete a resource from the database. |
| Method | discover |
Search for resources by a filter function. This goes through all resources in the database and applies the filter function to each resource. If the filter function returns True, the resource is added to the result list. |
| Method | get |
Get an action representation by resource ID. |
| Method | get |
Return all action representations. |
| Method | get |
Return the batch notifications for a resource and notification URI. |
| Method | get |
Get an originator and its information from the database. |
| Method | get |
Get requests for a resource ID, or all requests. |
| Method | get |
Get a schedule from the database. |
| Method | get |
Get all schedules from the database. |
| Method | has |
Check if a resource exists in the database. |
| Method | insert |
Add a request to the requests database. |
| Method | insert |
Insert a resource into the database. |
| Method | prepare |
Prepare the PreparedStatements for various SQL operations. |
| Method | purge |
Purge the database. Remove all data |
| Method | purge |
Purge the statistics DB. |
| Method | remove |
Remove an action representation. |
| Method | remove |
Remove the batch notifications for a resource and notification URI. |
| Method | remove |
Remove a child resource from the childResources DB. |
| Method | remove |
Remove old requests from the database. |
| Method | remove |
Remove an originator from the database. |
| Method | remove |
Remove a schedule from the database. |
| Method | remove |
Remove a subscription representation from the database. |
| Method | search |
Search for action representations by subject. |
| Method | search |
Search and return all resources that match the given dictionary/document. |
| Method | search |
Search for child resources by parent resource ID and optional type. |
| Method | search |
Search for an resource ID OR for a structured name in the identifiers DB. |
| Method | search |
Search for resources by structured resource name, resource ID, CSE-ID, parent resource ID, resource type, or application entity ID. |
| Method | search |
Search for schedules in the database. |
| Method | search |
Search for statistics. |
| Method | search |
Search for subscription representations by resource ID or parent resource ID. |
| Method | start |
Start the PostgreSQLBinding. |
| Method | update |
Update an action representation. |
| Method | update |
Update a resource in the database. Only the fields that are not None will be updated. |
| Method | upgrade |
Upgrade the tables if necessary. |
| Method | upsert |
Update or insert an action representation. |
| Method | upsert |
Add a child resource to the childResources DB. |
| Method | upsert |
Insert or update an identifier into the identifiers DB and a structured resource name into the structuredResourceNames DB. |
| Method | upsert |
Update or insert a resource into the database. |
| Method | upsert |
Add or update a schedule in the database. |
| Method | upsert |
Update or insert statistics. |
| Method | upsert |
Update or insert a subscription representation into the database. |
| Method | validate |
Validate the configuration for the PostgreSQLBinding. |
| Class Variable | table |
The name of the table for actions. |
| Class Variable | table |
The name of the table for batch notifications. |
| Class Variable | table |
The name of the table for child resource mappings. |
| Class Variable | table |
The name of the table for identifier mappings. |
| Class Variable | table |
The name of the table for originators. |
| Class Variable | table |
The name of the table to store requests and responses. |
| Class Variable | table |
The name of the table for resources. |
| Class Variable | table |
The name of the table for schedules. |
| Class Variable | table |
The name of the table for statistic information. |
| Class Variable | table |
The name of the table for subscription mappings. |
| Instance Variable | db |
The database connection object. |
| Instance Variable | db |
The name of the database to connect to. |
| Instance Variable | db |
The hostname of the database server. |
| Instance Variable | db |
The password to connect to the database. |
| Instance Variable | db |
The port of the database server. |
| Instance Variable | db |
The schema to use in the database. |
| Instance Variable | db |
The username to connect to the database. |
| Method | _check |
Check if the database connection is open. |
| Method | _execute |
Execute a prepared statement. |
| Method | _fetch |
Fetch the first elements from all rows from the database cursor. |
| Method | _fetch |
Fetch one number from the database cursor. |
| Method | _fetch |
Fetch the first element from the first row from the database cursor. |
Add a batch notification to the database.
| Parameters | |
batchJSON | The batch notification to add. |
| Returns | |
bool | True if the batch notification was added, False otherwise. |
Add an originator to the database.
| Parameters | |
originatorJSON | The originator structure to add. |
originator:str | The originator to add. |
| Returns | |
bool | Boolean value to indicate success or failure. |
Backup the database to a directory.
| Parameters | |
dir:str | The directory to backup to. |
| Returns | |
bool | Boolean value to indicate success or failure. |
Configure the PostgreSQLBinding with the provided configuration.
| Parameters | |
config:Configuration | The configuration object containing the settings for the PostgreSQLBinding. |
Return the number of batch notifications for a resource and notification URI.
| Parameters | |
ri:str | The resource ID of the resource. |
nu:str | The notification URI. |
| Returns | |
int | The number of batch notifications for the resource and notification URI. |
Delete an identifier from the identifiers DB.
| Parameters | |
ri:str | The resource ID of the resource. |
srn:str | The structured resource name of the resource. |
Remnove all stored requests from the database.
| Parameters | |
ri:str | None | Optional resouce ID. Only requests for this resource ID will be deleted. |
Search for resources by a filter function. This goes through all resources in the database and applies the filter function to each resource. If the filter function returns True, the resource is added to the result list.
| Parameters | |
func:Callable[ | The filter function to use. |
| Returns | |
list[ | A list of found resource documents, or an empty list. |
Get an action representation by resource ID.
| Parameters | |
ri:str | The resource ID of the action representation. |
| Returns | |
JSON | None | The action representation, or None if not found. |
Return all action representations.
| Returns | |
list[ | A list of action representations, or None if not found. |
Return the batch notifications for a resource and notification URI.
| Parameters | |
ri:str | The resource ID of the resource. |
nu:str | The notification URI. |
| Returns | |
list[ | A list of batch notifications for the resource and notification URI. |
Get an originator and its information from the database.
| Parameters | |
originator:str | The originator to search for. |
| Returns | |
tuple[ | Tuple containing the originator and its type, or None if not found. |
Get requests for a resource ID, or all requests.
| Parameters | |
ri:str | None | The target resource's resource ID. If None or empty, then all requests are returned |
| Returns | |
list[ | List of Documents. May be empty. |
Get a schedule from the database.
| Parameters | |
ri:str | The resource ID of the schedule. |
| Returns | |
JSON | None | The schedule, or None if not found. |
str | None = None, srn: str | None = None, ty: int | None = None) -> bool:
¶
Check if a resource exists in the database.
Only one of the parameters may be used at a time. The order of precedence is: structured resource name, resource ID, resource type.
| Parameters | |
ri:str | None | A resource ID. |
srn:str | None | A structured resource name. |
ty:int | None | A resource type. |
| Returns | |
bool | True if the resource exists, False otherwise. |
Add a request to the requests database.
| Parameters | |
req:JSON | The request to store. |
ts:float | The timestamp of the request. |
| Returns | |
bool | Boolean value to indicate success or failure. |
Insert a resource into the database.
| Parameters | |
resource:JSON | The resource to insert. |
ri:str | The resource ID of the resource. |
Prepare the PreparedStatements for various SQL operations.
This method is called after the database connection is established and the tables are created. It prepares the SQL statements for the various operations that can be performed on the database. This includes inserting, updating, and deleting resources, identifiers, child resources, and subscriptions.
Note that prepared statements are only usable within the same connection. Therefore, this method should be called after the connection is established.
Remove an action representation.
| Parameters | |
ri:str | The action's resource ID. |
| Returns | |
bool | True if the action representation was removed, False otherwise. |
Remove the batch notifications for a resource and notification URI.
| Parameters | |
ri:str | The resource ID of the resource. |
nu:str | The notification URI. |
| Returns | |
bool | True if the batch notifications were removed, False otherwise. |
Remove a child resource from the childResources DB.
| Parameters | |
ri:str | The resource ID of the resource. |
pi:str | The resource ID of the parent resource. |
Remove old requests from the database.
| Parameters | |
maxint | The maximum number of requests to keep. |
Remove an originator from the database.
| Parameters | |
originator:str | The originator to remove. |
| Returns | |
bool | Boolean value to indicate success or failure. |
Remove a schedule from the database.
| Parameters | |
ri:str | The resource ID of the schedule to remove. |
| Returns | |
bool | True if the schedule was removed, False otherwise. |
Remove a subscription representation from the database.
| Parameters | |
ri:str | The resource ID of the original SUB resource. |
| Returns | |
bool | True if the subscription representation was removed, False otherwise. |
Search for action representations by subject.
| Parameters | |
subjectstr | The resource ID of the action representation's subject. |
| Returns | |
Sequence[ | A list of action representations, or an empty list if not found. |
Search and return all resources that match the given dictionary/document.
| Parameters | |
dct:dict | The dictionary/document to search for. |
| Returns | |
list[ | A list of found resources, or an empty list. |
str, ty: ResourceTypes | list[ ResourceTypes] | None = None) -> list[ str]:
¶
Search for child resources by parent resource ID and optional type.
| Parameters | |
pi:str | The parent resource ID. |
ty:ResourceTypes | list[ | The resource type of the child resources to search for, or a list of resource types. |
| Returns | |
list[ | A list of child resource IDs, or an empty list if not found. |
Search for an resource ID OR for a structured name in the identifiers DB.
Either ri or srn shall be given. If both are given then srn is taken.
| Parameters | |
ri:str | None | Resource ID to search for. |
srn:str | None | Structured path to search for. |
| Returns | |
list[ | A list of found identifier documents (see upsertIdentifier), or an empty list if not found. |
str | None = None, csi: str | None = None, srn: str | None = None, pi: str | None = None, ty: int | None = None, aei: str | None = None) -> list[ JSON]:
¶
Search for resources by structured resource name, resource ID, CSE-ID, parent resource ID, resource type, or application entity ID.
Only one of the parameters may be used at a time. The order of precedence is: structured resource name, resource ID, CSE-ID, structured resource name, parent resource ID, resource type, application entity ID.
| Parameters | |
ri:str | None | A resource ID. |
csi:str | None | A CSE ID. |
srn:str | None | A structured resource name. |
pi:str | None | A parent resource ID. |
ty:int | None | A resource type. |
aei:str | None | An application entity ID. |
| Returns | |
list[ | A list of found resource documents, or an empty list. |
Search for schedules in the database.
| Parameters | |
pi:str | The resource ID of the parent resource. |
| Returns | |
list[ | List of Documents. May be empty. |
str | None = None, pi: str | None = None) -> list[ JSON] | None:
¶
Search for subscription representations by resource ID or parent resource ID.
Only one of the parameters may be used at a time. The order of precedence is: resource ID, parent resource ID.
| Parameters | |
ri:str | None | A resource ID. |
pi:str | None | A parent resource ID. |
| Returns | |
list[ | A list of found subscription representations, or None. |
Update an action representation.
| Parameters | |
actionJSON | The action representation to update. |
| Returns | |
bool | True if the action representation was updated, False otherwise. |
Update or insert an action representation.
| Parameters | |
actionJSON | The action representation to update or insert. |
ri:str | The resource ID of the action representation. |
| Returns | |
bool | True if the action representation was updated or inserted, False otherwise. |
Add a child resource to the childResources DB.
| Parameters | |
childJSON | The resource to add as a child. |
ri:str | The resource ID of the resource. |
JSON, structuredPathMapping: JSON, ri: str, srn: str):
¶
Insert or update an identifier into the identifiers DB and a structured resource name into the structuredResourceNames DB.
| Parameters | |
identifierJSON | The identifier mapping to insert. |
structuredJSON | The structured path mapping to insert. |
ri:str | The resource ID of the resource. |
srn:str | The structured resource name of the resource. |
Update or insert a resource into the database.
| Parameters | |
resource:JSON | The resource to upate or insert. |
ri:str | The resource ID of the resource. |
Add or update a schedule in the database.
| Parameters | |
schedule:JSON | The schedule to store. |
ri:str | The resource ID of the schedule. |
| Returns | |
bool | True if the schedule was added or updated, False otherwise. |
Update or insert statistics.
| Parameters | |
stats:JSON | The statistics to update or insert. |
| Returns | |
bool | True if the statistics were updated or inserted, False otherwise. |
Validate the configuration for the PostgreSQLBinding.
| Parameters | |
config:Configuration | The configuration object containing the settings for the PostgreSQLBinding. |
| Raises | |
ConfigurationError | If the configuration is invalid. |
Execute a prepared statement.
This is the main method to execute a prepared statement. It will execute the statement with the given arguments and return the result of the closure, if one is provided.
Almost all database operations are done through this method.
| Parameters | |
statement:str | The name of the prepared statement to execute and its parameters. |
args:tuple | The arguments to pass to the prepared statement. This must be a tuple. |
closure:Callable | None | An optional closure callback to process the result of the query. This closure will be passed the cursor object and should return the result of the query. |
| Returns | |
Any | The result of the closure, if one is provided, or True if no closure is provided. |
Fetch the first elements from all rows from the database cursor.
| Parameters | |
cursor:PsyCursor | The database cursor to fetch the rows from. |
| Returns | |
list[ | The fetched rows, or an empty list if no rows were fetched. |
Fetch one number from the database cursor.
| Parameters | |
cursor:PsyCursor | The database cursor to fetch the number from. |
| Returns | |
int | The fetched number, or None if no number was fetched. |
Fetch the first element from the first row from the database cursor.
| Parameters | |
cursor:PsyCursor | The database cursor to fetch the row from. |
asbool | Whether to return the row as a list or not. |
| Returns | |
Any | list[ | The fetched row as a single object or in a list, or None or an empty list if no row was fetched. |