![]() |
Fledge
An open source edge computing platform for industrial users
|
Public Member Functions | |
Connection () | |
Create a database connection. More... | |
~Connection () | |
Destructor for the database connection. More... | |
bool | retrieve (const std::string &schema, const std::string &table, const std::string &condition, std::string &resultSet) |
bool | retrieveReadings (const std::string &condition, std::string &resultSet) |
int | insert (const std::string &table, const std::string &data) |
Insert data into a table. | |
int | update (const std::string &table, const std::string &data) |
int | deleteRows (const std::string &table, const std::string &condition) |
int | appendReadings (const char *readings) |
Append a set of readings to the readings table. | |
bool | fetchReadings (unsigned long id, unsigned int blksize, std::string &resultSet) |
Fetch a block of readings from the reading table. More... | |
unsigned int | purgeReadings (unsigned long age, unsigned int flags, unsigned long sent, std::string &results) |
Purge readings from the reading table. | |
unsigned int | purgeReadingsByRows (unsigned long rowcount, unsigned int flags, unsigned long sent, std::string &results) |
Purge readings from the reading table leaving a number of rows equal to the parameter rows. More... | |
unsigned long | purgeOperation (const char *sql, const char *logSection, const char *phase, bool retrieve) |
Execute a SQL command for the purge task. | |
long | tableSize (const std::string &table) |
void | setTrace (bool flag) |
Enable or disable the tracing of SQL statements. More... | |
int | create_table_snapshot (const std::string &table, const std::string &id) |
int | load_table_snapshot (const std::string &table, const std::string &id) |
int | delete_table_snapshot (const std::string &table, const std::string &id) |
bool | get_table_snapshots (const std::string &table, std::string &resultSet) |
bool | aggregateQuery (const rapidjson::Value &payload, std::string &resultSet) |
int | create_schema (const std::string &payload) |
Create schema of tables. More... | |
bool | findSchemaFromDB (const std::string &service, const std::string &name, std::string &resultSet) |
Find existing payload schema from the DB fledge.service_schema table. More... | |
unsigned int | purgeReadingsAsset (const std::string &asset) |
void | setMaxReadingRows (long rows) |
bool | parseDatabaseStorageSchema (int &version, const std::string &res, std::unordered_map< std::string, std::unordered_set< columnRec, columnRecHasher, columnRecComparator > > &tableColumnMap, std::unordered_map< std::string, std::vector< std::string > > &tableIndexMap, bool &schemaCreationRequest) |
This function parses the fledge.service_schema table payload retrieved in and outputs a set of data structures containg the information about the tables and their columns and indexes. More... | |
Connection (ConnectionManager *manager) | |
Create a SQLite3 database connection. More... | |
bool | createSchema (const std::string &schema) |
Create schema and populate with tables and indexes as defined in the JSON schema definition. More... | |
bool | retrieve (const std::string &schema, const std::string &table, const std::string &condition, std::string &resultSet) |
int | insert (const std::string &schema, const std::string &table, const std::string &data) |
Insert data into a table. | |
int | update (const std::string &schema, const std::string &table, const std::string &data) |
int | deleteRows (const std::string &schema, const std::string &table, const std::string &condition) |
int | create_table_snapshot (const std::string &table, const std::string &id) |
int | load_table_snapshot (const std::string &table, const std::string &id) |
int | delete_table_snapshot (const std::string &table, const std::string &id) |
bool | get_table_snapshots (const std::string &table, std::string &resultSet) |
int | appendReadings (const char *readings) |
int | readingStream (ReadingStream **readings, bool commit) |
Append a stream of readings to SQLite db. More... | |
bool | fetchReadings (unsigned long id, unsigned int blksize, std::string &resultSet) |
bool | retrieveReadings (const std::string &condition, std::string &resultSet) |
unsigned int | purgeReadings (unsigned long age, unsigned int flags, unsigned long sent, std::string &results) |
unsigned int | purgeReadingsByRows (unsigned long rowcount, unsigned int flags, unsigned long sent, std::string &results) |
long | tableSize (const std::string &table) |
void | setTrace (bool) |
bool | formatDate (char *formatted_date, size_t formatted_date_size, const char *date) |
bool | aggregateQuery (const rapidjson::Value &payload, std::string &resultSet) |
bool | getNow (std::string &Now) |
sqlite3 * | getDbHandle () |
void | setUsedDbId (int dbId) |
Append a set of readings to the readings table. | |
void | shutdownAppendReadings () |
Wait until all the threads executing the appendReadings are shutted down. | |
unsigned int | purgeReadingsAsset (const std::string &asset) |
bool | vacuum () |
Execute a SQLite VACUUM command on the database. More... | |
bool | supportsReadings () |
bool | createSchema (const std::string &schema) |
bool | retrieve (const std::string &schema, const std::string &table, const std::string &condition, std::string &resultSet) |
int | insert (const std::string &schema, const std::string &table, const std::string &data) |
int | update (const std::string &schema, const std::string &table, const std::string &data) |
int | deleteRows (const std::string &schema, const std::string &table, const std::string &condition) |
int | create_table_snapshot (const std::string &table, const std::string &id) |
int | load_table_snapshot (const std::string &table, const std::string &id) |
int | delete_table_snapshot (const std::string &table, const std::string &id) |
bool | get_table_snapshots (const std::string &table, std::string &resultSet) |
int | appendReadings (const char *readings) |
int | readingStream (ReadingStream **readings, bool commit) |
bool | fetchReadings (unsigned long id, unsigned int blksize, std::string &resultSet) |
bool | retrieveReadings (const std::string &condition, std::string &resultSet) |
unsigned int | purgeReadings (unsigned long age, unsigned int flags, unsigned long sent, std::string &results) |
unsigned int | purgeReadingsByRows (unsigned long rowcount, unsigned int flags, unsigned long sent, std::string &results) |
long | tableSize (const std::string &table) |
void | setTrace (bool) |
bool | formatDate (char *formatted_date, size_t formatted_date_size, const char *date) |
bool | aggregateQuery (const rapidjson::Value &payload, std::string &resultSet) |
bool | getNow (std::string &Now) |
unsigned int | purgeReadingsAsset (const std::string &asset) |
bool | vacuum () |
void | setPurgeBlockSize (unsigned long purgeBlockSize) |
Static Public Member Functions | |
static bool | formatDate (char *formatted_date, size_t formatted_date_size, const char *date) |
Format a date to a fixed format with milliseconds, microseconds and timezone expressed, examples : More... | |
Connection::Connection | ( | ) |
Create a database connection.
Create a SQLite3 database connection.
Make a connection to the database and check backend connection was successfully made Note: we assume the database already exists, so the flag SQLITE_OPEN_CREATE is not added in sqlite3_open_v2 call
Connection::~Connection | ( | ) |
Destructor for the database connection.
Close the connection to Postgres
Close the connection to SQLite3 db
Connection::Connection | ( | ConnectionManager * | manager | ) |
Create a SQLite3 database connection.
Make a connection to the database and check backend connection was successfully made Note: we assume the database already exists, so the flag SQLITE_OPEN_CREATE is not added in sqlite3_open_v2 call
int Connection::create_schema | ( | const std::string & | payload | ) |
Create schema of tables.
payload | The payload containing information about schema of tables to create |
bool Connection::createSchema | ( | const std::string & | schema | ) |
Create schema and populate with tables and indexes as defined in the JSON schema definition.
schema | The schema defintion as a JSON document containing information about schema of tables to create |
bool Connection::fetchReadings | ( | unsigned long | id, |
unsigned int | blksize, | ||
std::string & | resultSet | ||
) |
Fetch a block of readings from the reading table.
Fetch a block of readings from the reading table It might not work with SQLite 3.
Fetch, used by the north side, returns timestamp in UTC.
NOTE : it expects to handle a date having a fixed format with milliseconds, microseconds and timezone expressed, like for example :
2019-01-11 15:45:01.123456+01:00
bool Connection::findSchemaFromDB | ( | const std::string & | service, |
const std::string & | schema, | ||
std::string & | resultSet | ||
) |
Find existing payload schema from the DB fledge.service_schema table.
service | The string containing service name |
name | The string containing schema name |
|
static |
Format a date to a fixed format with milliseconds, microseconds and timezone expressed, examples :
case - formatted |2019-01-01 10:01:01.000000+00:00| date |2019-01-01 10:01:01| case - formatted |2019-02-01 10:02:01.000000+00:00| date |2019-02-01 10:02:01.0| case - formatted |2019-02-02 10:02:02.841000+00:00| date |2019-02-02 10:02:02.841| case - formatted |2019-02-03 10:02:03.123456+00:00| date |2019-02-03 10:02:03.123456| case - formatted |2019-03-01 10:03:01.100000+00:00| date |2019-03-01 10:03:01.1+00:00| case - formatted |2019-03-02 10:03:02.123000+00:00| date |2019-03-02 10:03:02.123+00:00| case - formatted |2019-03-03 10:03:03.123456+00:00| date |2019-03-03 10:03:03.123456+00:00| case - formatted |2019-03-04 10:03:04.123456+01:00| date |2019-03-04 10:03:04.123456+01:00| case - formatted |2019-03-05 10:03:05.123456-01:00| date |2019-03-05 10:03:05.123456-01:00| case - formatted |2019-03-04 10:03:04.123456+02:30| date |2019-03-04 10:03:04.123456+02:30| case - formatted |2019-03-05 10:03:05.123456-02:30| date |2019-03-05 10:03:05.123456-02:30|
out | false if the date is invalid |
bool Connection::parseDatabaseStorageSchema | ( | int & | version, |
const std::string & | res, | ||
std::unordered_map< std::string, std::unordered_set< columnRec, columnRecHasher, columnRecComparator > > & | tableColumnMap, | ||
std::unordered_map< std::string, std::vector< std::string > > & | tableIndexMap, | ||
bool & | schemaCreationRequest | ||
) |
This function parses the fledge.service_schema table payload retrieved in and outputs a set of data structures containg the information about the tables and their columns and indexes.
[out] | version | version retrieved form payload |
[in] | res | output containing payload information |
[out] | tableColumnMap | map[tablename —> set of columns] |
[out] | tableIndexMap | map[tablename —> indexes] where each index is a comma separated string of columns |
unsigned int Connection::purgeReadingsByRows | ( | unsigned long | rowcount, |
unsigned int | flags, | ||
unsigned long | sent, | ||
std::string & | results | ||
) |
Purge readings from the reading table leaving a number of rows equal to the parameter rows.
Purge readings from the reading table.
int Connection::readingStream | ( | ReadingStream ** | readings, |
bool | commit | ||
) |
Append a stream of readings to SQLite db.
readings | readings to store into the SQLite db |
commit | if true a database commit is executed and a new transaction will be opened at the next execution |
TODO: the current code should be adapted to use the multi databases/tables implementation
readings | readings to store into the SQLite db |
commit | if true a database commit is executed and a new transaction will be opened at the next execution |
|
inline |
Enable or disable the tracing of SQL statements.
flag | Desired state of the SQL trace flag |
bool Connection::vacuum | ( | ) |
Execute a SQLite VACUUM command on the database.
Add a vacuum funtion, this is not needed for SQLite In Memory, but is here to satisfy the interface requirement.