Requires database operations are implemented in the database module.
Note that most table data entries are immutable. This means that changing the current value is actually an INSERT operation in the database. Operations that guarantee table immutability are referred to as conformant. Operations that do not guarantee table immutability are referred to as non-conformant. Non-conformant operation must be logged to preserve a record of table integrity.
In general there are four operations allowed on tables:
The add operation defines a new entry in a table. Because all data is immutable and it must be possible to obtain the complete state of the system for any given time in the past, all set operations are implemented as add operations with table-specific semantics considered, e.g., add may require non-existence of a field value, and set may require existence of a field value.
The get operation obtains the data for an existing entry in a table.
The find operation obtains the record id for an entry in a table. By default, find operations obtain the most recently added entry that matches the search criteria. The result must be unique. If the result is empty, the return value is None. If the result is non-unique, the search fails with the error "result is not unique".
If the date and time have been changed using the set_clock operation, find operations obtain the record id that was in effect at the time.
The set operation implements changes to existing entries in a table. A set oeration inserts a new entry with a more recent created date/time. A set operation cannot change an existing record.
A number of table operations do not necessarily satisfy the immutability requirement for table operations. All non-conforming table operations must be logged in the log date using a conforming table operation.
-
CREATE: creation of new tables, fields, indexes, etc. -
INSERT: insertion of new records other than using anaddoperation -
UPDATE: update of existing records -
DELETE: delete of existing records -
ALTER: changes to tables, fields, indexes, etc. -
LOAD: bulk loading of data -
DUMP: bulk dumping of data
set_clock(datetime=None)
Sets the time at which the database entries are to be returned. Note that only get and find operations are affected by the clock. Setting the clock to None reset the clock to default behavior, i.e., obtain the most recent entry.
The config table stores data related to the general system configuration.
| Field name | Data type | Default value | Remarks |
|---|---|---|---|
| config_id | integer | autonum | primary key |
| system_id | integer | required | constraint key |
| name | text | required | |
| value | text | NULL | |
| created | datetime | autogen | insert time |
add_config(name,value)
The add_config operation creates a new configuration variable. If the variable exists, the add_config operation fails with the error "{name} exists"
The initial variables defined for TESS operations are the following:
| Name | Initial value |
|---|---|
| api-version | 1 |
| mechanism | AUCTION |
| interval | 300 |
| time-unit | h |
| currency-unit | $ |
| admin-email | [email protected] |
get_config(config_id)
The get_config operation gets the value for the specified config_id.
find_config(name)
The find_config operation obtains the current value of the config variable name. If the set_clock operation has been used, the value obtained will be for the datetime specified.
set_config(name,value)
The set_config operation sets the current value of a configuration variable. If the config entry name does not exist the operation fails with the error "{name} not found"
The device table stores data related to devices that participate in the TESS market operations.
| Field name | Data type | Default value | Remarks |
|---|---|---|---|
| device_id | integer | autonum | primary key |
| user_id | integer | required | constraint key |
| name | text | required | |
| unique_id | text | autogen | unique key |
| created | datetime | autogen | insert time |
The log table stores data related to non-conforming database operations during TESS market operations. Log entries are required for all events that are not otherwise recorded in other tables. The following events must be logged:
- Database creation
- Database backup
- Database restore
- Database operations that do not strictly conform to the database immutability requirement (e.g.,
INSERT,UPDATE,DELETE,ALTER).
The meter table stores data related to meters that record device behavior for the purpose of generating transactions.
The order table stores data related to buy and sell orders placed by devices.
The preference table stores data related to user preferences for mobile and web applications they user.
The price table stores data related to prices generated by market operations.
The resource table stores data related to resources that are available through the TESS market operations.
The setting table stores data related to settings for devices that users own.
The system table stores data related to systems that participate in the TESS market operations.
The token table stores data related to access tokens generated by users and devices.
The transaction table stores data related to transactions arising from device metering.
The user table stores data related to user that participate in the TESS market operations.