From cd966d8ea7ff205a47776d6a2ce4dc4aeec0ecbd Mon Sep 17 00:00:00 2001 From: Paul Tikken Date: Thu, 11 Apr 2024 15:02:42 +0000 Subject: [PATCH] [CveXplore-234] reformat --- CveXplore/VERSION | 2 +- .../database/connection/sqlbase/sql_base.py | 68 +------------------ .../database/connection/sqlbase/sql_client.py | 37 ++++++++++ .../connection/sqlbase/sql_client_base.py | 30 ++++++++ 4 files changed, 69 insertions(+), 68 deletions(-) create mode 100644 CveXplore/database/connection/sqlbase/sql_client.py create mode 100644 CveXplore/database/connection/sqlbase/sql_client_base.py diff --git a/CveXplore/VERSION b/CveXplore/VERSION index 112972b6..5f0596e5 100644 --- a/CveXplore/VERSION +++ b/CveXplore/VERSION @@ -1 +1 @@ -0.3.24.dev11 \ No newline at end of file +0.3.24.dev12 \ No newline at end of file diff --git a/CveXplore/database/connection/sqlbase/sql_base.py b/CveXplore/database/connection/sqlbase/sql_base.py index 2644e034..1e650e0a 100644 --- a/CveXplore/database/connection/sqlbase/sql_base.py +++ b/CveXplore/database/connection/sqlbase/sql_base.py @@ -1,71 +1,5 @@ -import logging -from abc import ABC, abstractmethod - -from sqlalchemy import insert - -from CveXplore.core.database_models.models import Cpe, Info from CveXplore.database.connection.base.db_connection_base import DatabaseConnectionBase -from CveXplore.database.connection.sqlbase.connection import Session - - -class SQLClientBase(ABC): - def __init__(self, logger_name: str): - self.logger = logging.getLogger(logger_name) - - def __repr__(self): - return f"<<{self.__class__.__name__}>>" - - @abstractmethod - def bulk_write(self, *args, **kwargs): - raise NotImplementedError - - @abstractmethod - def insert_many(self, *args, **kwargs): - raise NotImplementedError - - @abstractmethod - def delete_one(self, *args, **kwargs): - raise NotImplementedError - - @abstractmethod - def drop(self, *args, **kwargs): - raise NotImplementedError - - @abstractmethod - def update_one(self, *args, **kwargs): - raise NotImplementedError - - -class SQLClient(SQLClientBase): - def __init__(self, collection_name: str): - super().__init__(logger_name=__name__) - self.session = Session - self.collection_name = collection_name - - self.model_mapping = {"info": Info, "cpe": Cpe} - - def bulk_write(self, write_entries: list, ordered: bool = False): - with self.session() as session: - session.execute( - insert(self.model_mapping[self.collection_name]), write_entries - ) - session.commit() - - def insert_many(self, write_entries: list, ordered: bool = False): - with self.session() as session: - session.execute( - insert(self.model_mapping[self.collection_name]), write_entries - ) - session.commit() - - def delete_one(self, *args, **kwargs): - pass - - def drop(self, *args, **kwargs): - pass - - def update_one(self, *args, **kwargs): - pass +from CveXplore.database.connection.sqlbase.sql_client import SQLClient class SQLBaseConnection(DatabaseConnectionBase): diff --git a/CveXplore/database/connection/sqlbase/sql_client.py b/CveXplore/database/connection/sqlbase/sql_client.py new file mode 100644 index 00000000..e0474823 --- /dev/null +++ b/CveXplore/database/connection/sqlbase/sql_client.py @@ -0,0 +1,37 @@ +from sqlalchemy import insert + +from CveXplore.core.database_models.models import Cpe, Info +from CveXplore.database.connection.sqlbase.connection import Session +from CveXplore.database.connection.sqlbase.sql_client_base import SQLClientBase + + +class SQLClient(SQLClientBase): + def __init__(self, collection_name: str): + super().__init__(logger_name=__name__) + self.session = Session + self.collection_name = collection_name + + self.model_mapping = {"info": Info, "cpe": Cpe} + + def bulk_write(self, write_entries: list, ordered: bool = False): + with self.session() as session: + session.execute( + insert(self.model_mapping[self.collection_name]), write_entries + ) + session.commit() + + def insert_many(self, write_entries: list, ordered: bool = False): + with self.session() as session: + session.execute( + insert(self.model_mapping[self.collection_name]), write_entries + ) + session.commit() + + def delete_one(self, *args, **kwargs): + pass + + def drop(self, *args, **kwargs): + pass + + def update_one(self, *args, **kwargs): + pass diff --git a/CveXplore/database/connection/sqlbase/sql_client_base.py b/CveXplore/database/connection/sqlbase/sql_client_base.py new file mode 100644 index 00000000..8dc86bb3 --- /dev/null +++ b/CveXplore/database/connection/sqlbase/sql_client_base.py @@ -0,0 +1,30 @@ +import logging +from abc import ABC, abstractmethod + + +class SQLClientBase(ABC): + def __init__(self, logger_name: str): + self.logger = logging.getLogger(logger_name) + + def __repr__(self): + return f"<<{self.__class__.__name__}>>" + + @abstractmethod + def bulk_write(self, *args, **kwargs): + raise NotImplementedError + + @abstractmethod + def insert_many(self, *args, **kwargs): + raise NotImplementedError + + @abstractmethod + def delete_one(self, *args, **kwargs): + raise NotImplementedError + + @abstractmethod + def drop(self, *args, **kwargs): + raise NotImplementedError + + @abstractmethod + def update_one(self, *args, **kwargs): + raise NotImplementedError