DataBase¶
-
class
BinanceWatch.storage.DataBase.DataBase(name: str)[source]¶ This class will be used to interact with sqlite3 databases without having to generates sqlite commands
-
__init__(name: str)[source]¶ Initialise a DataBase instance
- Parameters
name (str) – name of the database
-
add_row(table: BinanceWatch.storage.tables.Table, row: Tuple, auto_commit: bool = True, update_if_exists: bool = False)[source]¶ Add a row to a table
- Parameters
table (Table) – table to add a row to
row (Tuple) – values to add to the database
auto_commit (bool) – if the database state should be saved after the changes
update_if_exists (bool) – if an integrity error is raised and this parameter is true, will update the existing row
- Returns
None
- Return type
None
-
add_rows(table: BinanceWatch.storage.tables.Table, rows: List[Tuple], auto_commit: bool = True, update_if_exists: bool = False)[source]¶ Add several rows to a table
- Parameters
table (Table) – table to add a row to
rows (List[Tuple]) – list of values to add to the database
auto_commit (bool) – if the database state should be saved after the changes
update_if_exists (bool) – if an integrity error is raised and this parameter is true, will update the existing row
- Returns
None
- Return type
None
-
create_table(table: BinanceWatch.storage.tables.Table)[source]¶ Create a table in the database
- Parameters
table (Table) – Table instance with the config of the table to create
- Returns
None
- Return type
None
-
drop_all_tables()[source]¶ Drop all the tables existing in the database
- Returns
None
- Return type
None
-
drop_table(table: Union[BinanceWatch.storage.tables.Table, str])[source]¶ Delete a table from the database
- Parameters
table (Union[Table, str]) – table or table name to drop
- Returns
None
- Return type
None
-
get_all_rows(table: BinanceWatch.storage.tables.Table) → List[Tuple][source]¶ Get all the rows of a table
- Parameters
table (Table) – table to get the rows from
- Returns
all the rows of the table
- Return type
List[Tuple]
-
get_all_tables() → List[Tuple][source]¶ Return all the tables existing in the database
- Returns
tables descriptions
- Return type
List[Tuple]
-
get_conditions_rows(table: BinanceWatch.storage.tables.Table, selection: Union[str, List[str]] = '*', conditions_list: Optional[List[Tuple[str, BinanceWatch.storage.DataBase.SQLConditionEnum, Any]]] = None, order_list: Optional[List[str]] = None) → List[Tuple][source]¶ Select rows with optional conditions and optional order
- Parameters
table (Table) – table to select the rows from
selection (Union[str, List[str]]) – list of column or SQL type selection
conditions_list (Optional[List[Tuple[str, SQLConditionEnum, Any]]]) – list of conditions to select the row
order_list (Optional[List[str]]) – List of SQL type order by
- Returns
the selected rows
- Return type
List[Tuple]
-
static
get_create_cmd(table: BinanceWatch.storage.tables.Table) → str[source]¶ Return the command in string format to create a table in the database
- Parameters
table (Table) – Table instance with the config if the table to create
- Returns
execution command for the table creation
- Return type
str
-
get_row_by_key(table: BinanceWatch.storage.tables.Table, key_value) → Optional[Tuple][source]¶ Get the row identified by a primary key value from a table
- Parameters
table (Table) – table to fetch the key from
key_value (Any) – value of the primary key
- Returns
the raw row of of the table
- Return type
Optional[Tuple]
-
update_row(table: BinanceWatch.storage.tables.Table, row: Tuple, auto_commit=True)[source]¶ Update the value of a row in a table
- Parameters
table (Table) – table to get updated
row (Tuple) – values to update
auto_commit (bool) – if the database state should be saved after the changes
- Returns
None
- Return type
None
-