From 38db28b92a3c0e75ac6f48d8f705f3b3b1526bc4 Mon Sep 17 00:00:00 2001 From: andrei Date: Fri, 11 Feb 2022 16:31:56 +0200 Subject: [PATCH] Added connection dict object, where is stored all connections --- planetmint/backend/tarantool/database.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/planetmint/backend/tarantool/database.py b/planetmint/backend/tarantool/database.py index 9819787..43c9734 100644 --- a/planetmint/backend/tarantool/database.py +++ b/planetmint/backend/tarantool/database.py @@ -4,11 +4,26 @@ from planetmint.backend.tarantool.utils import run class TarantoolDB: - def __init__(self, host, port, username, password): - self.conn = tarantool.connect(host=host, port=port, user=username, password=password) + def __init__(self, host: str, port: int, username: str, password: str): + self.db_connect = tarantool.connect(host=host, port=port, user=username, password=password) + self._spaces = { + "abci_chains": self.db_connect.space("abci_chains"), + "assets": self.db_connect.space("assets"), + "blocks": {"blocks": self.db_connect.space("blocks"), "blocks_tx": self.db_connect.space("blocks_tx")}, + "elections": self.db_connect.space("elections"), + "meta_data": self.db_connect.space("meta_data"), + "pre_commits": self.db_connect.space("pre_commits"), + "validators": self.db_connect.space("validators"), + "transactions": { + "transactions": self.db_connect.space("transactions"), + "inputs": self.db_connect.space("inputs"), + "outputs": self.db_connect.space("outputs"), + "keys": self.db_connect.space("keys") + } + } - def connect_to_sapce(self, spacename): - self.conn.space(spacename) + def get_space(self, spacename: str): + return self._spaces[spacename] def init_tarantool():