C++ REST database module#

namespace db#

Namespace including the API Eigen Example Server REST DB functionalities.

Enums

enum class DbTypes#

Enum holding the types of variables handled.

Values:

enumerator VECTOR#

The Vector type.

enumerator MATRIX#

The Matrix type.

Functions

std::string dbtype_to_str(const DbTypes &value)#

Method for returning the enum value as a std::string.

Parameters:

value – the enum value we want as a std::string.

Returns:

std::string

static int callback(void *value, int argc, char **argv, char **azColName)#

Callback to be executed after function is complete.

Parameters:
  • value – pointer to the argument passed in sqlite3_exec.

  • argc – number of callbacks to process.

  • argv – values in each callback.

  • azColName – name of the cols in the callback.

Returns:

int

class RestDb#

Class for establishing a connection with the REST DB and interacting with it.

Public Functions

RestDb()#

Construct a new Rest Db object.

~RestDb()#

Destroy the Rest Db object.

long store_resource(const DbTypes &type, const std::string &input)#

Method for storing a Resource in the REST DB.

Parameters:
  • type – the type of resource processed.

  • input – the JSON request body from where the resource is parsed.

Returns:

long - the id of the inserted row in the DB.

std::string load_resource(const DbTypes &type, const int &input)#

Method in charge of loading a stored resource in the DB from a given ID.

Parameters:
  • type – the type of resource processed.

  • input – the id of the resource inside the DB.

Returns:

std::string - the resource loaded from the DB (as a string).

Private Functions

void initialize_db()#

Method for initializing the REST DB to be used.

Private Members

sqlite3 *_db#

A pointer to the DB connection.