Skip to content

Commit

Permalink
[CveXplore-234] reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
P-T-I committed Apr 11, 2024
1 parent 1156eec commit cd966d8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 68 deletions.
2 changes: 1 addition & 1 deletion CveXplore/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.24.dev11
0.3.24.dev12
68 changes: 1 addition & 67 deletions CveXplore/database/connection/sqlbase/sql_base.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
37 changes: 37 additions & 0 deletions CveXplore/database/connection/sqlbase/sql_client.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions CveXplore/database/connection/sqlbase/sql_client_base.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cd966d8

Please sign in to comment.