Database Operations
Learn about Zephyr's database operations.
Zephyr currently supports the following types of database interactions:
Write.
Read.
Update.
On the guest level, there is no auth to handle so this is pretty straightforward as you don't have to grant any special permissions.
Write
In the Zephyr VM, or better in the Mercury abstraction of the VM implementation, a write operation translates to a SQL insert statement and it is performed by providing a constructed DatabaseDerive
object to the EnvClient::put()
function:
In this case, "table" is a DatabaseDerive
object and represents a new row in the table.
Read
Reading means returning an iterator (a vec currently) over DatabaseDerive
elements, as many as the rows present in the requested table. It is done by simply calling EnvClient::read()
while inferring the requested table type (which will automatically translate to reading from the corresponding table):
Update
Updating lets you update a selection of the table by changing some rows with a new given one. You have to specify the conditions under which to change the rows, and the new row as a DatabaseDerive
element:
In this snippet, all rows where the hello
column equals to the message
ScVal will be updated with the row defined by table
.
Last updated