PostGreSQL Management
While Klave provides access to a tamper-proof NoSQL key-value datastore Ledger APIs, there are many use-cases that need a connection to a relational database outside of Klave hosting. To that intent, we manage a dedicated service hosted in an enclave that manages PostGreSQL connection, queries and executes transactions on your behalf.
Using PostGreSQL Interface from Applications
The Klave SDK exposes 4 different routes to interact with a PostGreSQL database hosted outside of Klave.
The set of operations is the following one:
Class | Operation | Parameters | Returns | Behavior |
---|---|---|---|---|
PostGreSQL | connectionString | host, dbname, user, password | uri | Builds the connection_string to be provided in the route connectionOpen. |
PostGreSQL | connectionOpen | connection_string | handle | This route returns the handle to the database. It's mandatory to open a connection before any query or execution. |
PostGreSQL | sqlQuery | connection_handle, query | value | Returns a string value which is the result of your specific query. |
PostGreSQL | sqlExec | connection_handle, command | value | Returns a string code indicating the completion of your command. |
Routes connectionOpen, sqlQuery and sqlExec have to be called within the context of a query (@query), as the result isn't deterministic.
Always run the connectionOpen route first to open an handle whose lifetime will be limited to the context of the query.
In AssemblyScript, these different routes can be accessed through the PostGreSQL
keyword. For example:
Output of a query is an object with fields
definition and resultset
arrays. You will find an example as defined below:
Last updated on