| 4 | from middle.mapexception import MapXploreException |
| 5 | |
| 6 | class DbConnector: |
| 7 | def __init__(self,*argv, **kwargs) -> None: |
| 8 | arguments = None |
| 9 | if len(kwargs) == 0: |
| 10 | arguments = argv[0] |
| 11 | else: |
| 12 | arguments = Connection() |
| 13 | for key,value in kwargs.items(): |
| 14 | setattr(arguments, key, value) |
| 15 | |
| 16 | self._delimiter = arguments.delimiter if hasattr(arguments, "delimiter") else "," |
| 17 | self._table= arguments.table if hasattr(arguments, "table") else None |
| 18 | self._database = arguments.database if hasattr(arguments, "database") else None |
| 19 | self._host = arguments.host |
| 20 | self._username = arguments.username |
| 21 | self._password = arguments.password |
| 22 | self._connection = Connection(server=arguments.host,username=arguments.username,password=arguments.password) |
| 23 | self._dbms = arguments.dbms |
| 24 | |
| 25 | |
| 26 | def _createDBEngine(self, database=None, connection=None): |
| 27 | con = None |
| 28 | try: |
| 29 | if database is None and self._database is not None: |
| 30 | database = self._database |
| 31 | |
| 32 | if self._dbms == 'postgres': |
| 33 | con = PostgreSQL(database.lower() if database is not None else None, self._connection if connection is None else connection) |
| 34 | elif self._dbms == 'sqlite': |
| 35 | con = SQLite(database, None) |
| 36 | if con: |
| 37 | con.test_connection() |
| 38 | except Exception as e: |
| 39 | raise e |
| 40 | |
| 41 | return con |
no outgoing calls
no test coverage detected