Trading System API  3.0
Library for Simulating and Deploying Trading and Investment Strategies
tsa::sqlite::database Class Reference

SQLite database object. Object of this class allow ts-api to read and write time series tables in an SQLite database file. More...

#include <TSASQLite.h>

Inheritance diagram for tsa::sqlite::database:
tsa::data_base tsa::object

Public Member Functions

 database (const tsa::os::path &path, const access_mode &permissions=sqlite::read_write_create, const cache_type &visibility=private_cache)
 Constructor.
 
 database (const special_t &in_memory, const access_mode &permissions=sqlite::read_write_create, const cache_type &visibility=private_cache)
 Constructor.
 
virtual void create_series_table (const std::string &table_name, const tsa::column_defs &) override
 Creates a new series table. A series table is a table that has a timestamp as first column. Recall that the timestamp is implicit to all series tables and must not be given as part of the columns definition. More...
 
virtual bool drop_series_table (const std::string &) override
 ??????? drop_table
 
virtual void series_append (const std::string &table_name, const tsa::mem_table &data) override
 Appends the records from the given m_table to a database table. This operation will fail if there is overal in the range of timestamps, or if the column structure does not match. More...
 
virtual void series_load (const std::string &table_name, tsa::mem_table &data, const date_time &from_timestamp, size_t num_records) override
 Loads a number of series records from a given database table into a mem_table (memory based table) object. More...
 
virtual date_time series_table_closest_timestamp_LOE (const date_time &ts, const std::string &table_name) override
 Returns the record timestamp that is closest to, but lower than, the given target timestamp. More...
 
virtual tsa::column_defs series_table_column_defs (const std::string &table_name) override
 Returns the column definition structure. More...
 
virtual date_time series_table_first_timestamp (const std::string &table_name) override
 Returns the timestamp of the first record in the table. More...
 
virtual date_time series_table_last_timestamp (const std::string &table_name) override
 Returns the timestamp of the last records in the table. More...
 
virtual bool table_exists (const std::string &) const override
 Returns true if a database table exists. More...
 
virtual bool table_has_data (const std::string &table_name) override
 Returns true if the table has records, false if empty. More...
 
virtual int64_t table_record_count (const std::string &table_name)
 Returns the number of records in the table. More...
 
virtual bool table_record_count_is_known (void) const
 Returns true if the database system knows the size (record count) of a table at all times, or whether it needs to iterate through the table to calculate the size. In the native fast::database knows the table size at all times, whereas SQL databases need to launch the 'select count(*)' command. More...
 
virtual void truncate_series_table (const std::string &table_name, const date_time &new_max_timestamp=date_time::min)
 Truncates a database table by deleting all records higher than a given new_max_timestamp. More...
 
virtual std::string type (void) const override
 Returns the 'type' of the database as a string, such as "sqlite", "postgresql" or the native "fast". More...
 
- Public Member Functions inherited from tsa::data_base
 data_base (void)
 Constructor.
 
virtual ~data_base (void)
 Destructor.
 
void copy_table_from (data_base &source_db, const std::string &source_table_name, const std::string &target_table_name, const table_copy_params &copy_prop=table_copy_params())
 Copies a table, potentially from one database to another, according to the given table_copy_properties object, which by default copies the entire table. See class table_copy_properties for more details. More...
 
void import (const file_import_rules__obsolete &import_properties)
 Imports records from a text file according to the given import properties. See class file_import_properties for more information. More...
 
void print_table_info (const std::string &table_name, std::ostream &stream)
 Prints basic information about the table. More...
 
bool series_columns_match (const std::string &table_name, const tsa::mem_table &m_table)
 Returns true if a database table has an identical column structure to a given mem_table. More...
 
- Public Member Functions inherited from tsa::object
 object (void)
 Constructor.
 
virtual ~object (void)
 Destructor.
 
const char * class_name (void) const
 Returns the class name as returned by the 'Real Time Type Information' (RTTI) mechanism. More...
 
bool has_same_class_as (const object &other) const
 Returns true if self has the same type as other object. More...
 

Detailed Description

SQLite database object. Object of this class allow ts-api to read and write time series tables in an SQLite database file.

Member Function Documentation

void tsa::sqlite::database::create_series_table ( const std::string table_name,
const tsa::column_defs columns 
)
overridevirtual

Creates a new series table. A series table is a table that has a timestamp as first column. Recall that the timestamp is implicit to all series tables and must not be given as part of the columns definition.

Parameters
table_nameThe name of the new series table.
columnsThe columnar structure.

Implements tsa::data_base.

void tsa::sqlite::database::series_append ( const std::string table_name,
const tsa::mem_table m_table 
)
overridevirtual

Appends the records from the given m_table to a database table. This operation will fail if there is overal in the range of timestamps, or if the column structure does not match.

Parameters
table_nameName of the target databse table.
m_tableThe memory based table.

Implements tsa::data_base.

void tsa::sqlite::database::series_load ( const std::string table_name,
tsa::mem_table mtable,
const date_time from_timestamp,
size_t  num_records 
)
overridevirtual

Loads a number of series records from a given database table into a mem_table (memory based table) object.

Parameters
table_nameName of the database table.
[in,out]mtableThe mem_table.
from_timestampThe timestamp of the first record to load.
num_recordsThe number of records to load.

Implements tsa::data_base.

date_time tsa::sqlite::database::series_table_closest_timestamp_LOE ( const date_time target,
const std::string table_name 
)
overridevirtual

Returns the record timestamp that is closest to, but lower than, the given target timestamp.

Parameters
targetThe target timestamp.
table_nameName of the table.
Returns
A date_time.

Implements tsa::data_base.

tsa::column_defs tsa::sqlite::database::series_table_column_defs ( const std::string table_name)
overridevirtual

Returns the column definition structure.

Parameters
table_nameName of the table.
Returns
A tsa::column_defs.

Implements tsa::data_base.

date_time tsa::sqlite::database::series_table_first_timestamp ( const std::string table_name)
overridevirtual

Returns the timestamp of the first record in the table.

Parameters
table_nameName of the table.
Returns
A date_time.

Implements tsa::data_base.

date_time tsa::sqlite::database::series_table_last_timestamp ( const std::string table_name)
overridevirtual

Returns the timestamp of the last records in the table.

Parameters
table_nameName of the table.
Returns
A date_time.

Implements tsa::data_base.

bool tsa::sqlite::database::table_exists ( const std::string table_name) const
overridevirtual

Returns true if a database table exists.

Parameters
table_nameName of the database table.
Returns
true if it exists.

Implements tsa::data_base.

bool tsa::sqlite::database::table_has_data ( const std::string table_name)
overridevirtual

Returns true if the table has records, false if empty.

Parameters
table_nameName of the table.
Returns
true if it succeeds, false if it fails.

Implements tsa::data_base.

int64_t tsa::sqlite::database::table_record_count ( const std::string table_name)
virtual

Returns the number of records in the table.

Parameters
table_nameName of the table.
Returns
An int64_t.

Implements tsa::data_base.

bool tsa::sqlite::database::table_record_count_is_known ( void  ) const
virtual

Returns true if the database system knows the size (record count) of a table at all times, or whether it needs to iterate through the table to calculate the size. In the native fast::database knows the table size at all times, whereas SQL databases need to launch the 'select count(*)' command.

Returns
bool.

Implements tsa::data_base.

void tsa::sqlite::database::truncate_series_table ( const std::string table_name,
const date_time new_max_timestamp = date_time::min 
)
virtual

Truncates a database table by deleting all records higher than a given new_max_timestamp.

Parameters
table_nameName of the table.
new_max_timestampThe new maximum record timestamp.

Implements tsa::data_base.

std::string tsa::sqlite::database::type ( void  ) const
overridevirtual

Returns the 'type' of the database as a string, such as "sqlite", "postgresql" or the native "fast".

Returns
A std::string.

Implements tsa::data_base.