DE-Lib 0.0.20__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- de_lib-0.0.20/DE_LIB.egg-info/PKG-INFO +68 -0
- de_lib-0.0.20/DE_LIB.egg-info/SOURCES.txt +55 -0
- de_lib-0.0.20/DE_LIB.egg-info/dependency_links.txt +1 -0
- de_lib-0.0.20/DE_LIB.egg-info/requires.txt +10 -0
- de_lib-0.0.20/DE_LIB.egg-info/top_level.txt +1 -0
- de_lib-0.0.20/DE_Lib/Cloud/__init__.py +0 -0
- de_lib-0.0.20/DE_Lib/DataBase/Azure.py +44 -0
- de_lib-0.0.20/DE_Lib/DataBase/Cache.py +74 -0
- de_lib-0.0.20/DE_Lib/DataBase/Firebird.py +45 -0
- de_lib-0.0.20/DE_Lib/DataBase/Informix.py +37 -0
- de_lib-0.0.20/DE_Lib/DataBase/Metadata.py +62 -0
- de_lib-0.0.20/DE_Lib/DataBase/MsSql.py +39 -0
- de_lib-0.0.20/DE_Lib/DataBase/MySql.py +42 -0
- de_lib-0.0.20/DE_Lib/DataBase/Oracle.py +111 -0
- de_lib-0.0.20/DE_Lib/DataBase/Postgres.py +39 -0
- de_lib-0.0.20/DE_Lib/DataBase/RedShift.py +42 -0
- de_lib-0.0.20/DE_Lib/DataBase/SQCipher.py +42 -0
- de_lib-0.0.20/DE_Lib/DataBase/SQLite.py +48 -0
- de_lib-0.0.20/DE_Lib/DataBase/__init__.py +0 -0
- de_lib-0.0.20/DE_Lib/Files/Avro.py +23 -0
- de_lib-0.0.20/DE_Lib/Files/Csv.py +64 -0
- de_lib-0.0.20/DE_Lib/Files/JSon.py +64 -0
- de_lib-0.0.20/DE_Lib/Files/Parquet.py +31 -0
- de_lib-0.0.20/DE_Lib/Files/Txt.py +64 -0
- de_lib-0.0.20/DE_Lib/Files/Xlsx.py +55 -0
- de_lib-0.0.20/DE_Lib/Files/__init__.py +0 -0
- de_lib-0.0.20/DE_Lib/Log/DE_LogEventos.py +533 -0
- de_lib-0.0.20/DE_Lib/Log/Level.py +77 -0
- de_lib-0.0.20/DE_Lib/Log/Log.py +470 -0
- de_lib-0.0.20/DE_Lib/Log/__init__.py +0 -0
- de_lib-0.0.20/DE_Lib/Utils/Cipher/Aes.py +65 -0
- de_lib-0.0.20/DE_Lib/Utils/Cipher/Argon.py +37 -0
- de_lib-0.0.20/DE_Lib/Utils/Cipher/Base64.py +48 -0
- de_lib-0.0.20/DE_Lib/Utils/Cipher/Cipher.py +300 -0
- de_lib-0.0.20/DE_Lib/Utils/Cipher/Fernet.py +81 -0
- de_lib-0.0.20/DE_Lib/Utils/Cipher/Gcm.py +78 -0
- de_lib-0.0.20/DE_Lib/Utils/Cipher/Pbkdf2.py +43 -0
- de_lib-0.0.20/DE_Lib/Utils/Cipher/Rsa.py +140 -0
- de_lib-0.0.20/DE_Lib/Utils/Cipher/__init__.py +0 -0
- de_lib-0.0.20/DE_Lib/Utils/Colors.py +203 -0
- de_lib-0.0.20/DE_Lib/Utils/DateUtils.py +215 -0
- de_lib-0.0.20/DE_Lib/Utils/Generic.py +249 -0
- de_lib-0.0.20/DE_Lib/Utils/SQL.py +34 -0
- de_lib-0.0.20/DE_Lib/Utils/System.py +50 -0
- de_lib-0.0.20/DE_Lib/Utils/WebHook.py +18 -0
- de_lib-0.0.20/DE_Lib/Utils/__init__.py +0 -0
- de_lib-0.0.20/DE_Lib/__init__.py +0 -0
- de_lib-0.0.20/LICENCE +21 -0
- de_lib-0.0.20/PKG-INFO +68 -0
- de_lib-0.0.20/README.md +41 -0
- de_lib-0.0.20/setup.cfg +4 -0
- de_lib-0.0.20/setup.py +25 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: DE_Lib
|
3
|
+
Version: 0.0.20
|
4
|
+
Summary: Biblioteca de funcionalidades
|
5
|
+
Home-page: https://github.com/DE-DATAx/DAX_DB.git
|
6
|
+
Author: Almir J Gomes
|
7
|
+
Author-email: almir.jg@hotmail.com
|
8
|
+
Description-Content-Type: text/markdown
|
9
|
+
License-File: LICENCE
|
10
|
+
Requires-Dist: fbd
|
11
|
+
Requires-Dist: cx_Oracle
|
12
|
+
Requires-Dist: JayDeBeApi
|
13
|
+
Requires-Dist: mysql.connector
|
14
|
+
Requires-Dist: psycopg2
|
15
|
+
Requires-Dist: pymssql
|
16
|
+
Requires-Dist: redshift-connector
|
17
|
+
Requires-Dist: SQLAlchemy==2.0.38
|
18
|
+
Requires-Dist: bcrypt==4.3.0
|
19
|
+
Requires-Dist: argon2-cffi==23.1.0
|
20
|
+
Dynamic: author
|
21
|
+
Dynamic: author-email
|
22
|
+
Dynamic: description
|
23
|
+
Dynamic: description-content-type
|
24
|
+
Dynamic: home-page
|
25
|
+
Dynamic: requires-dist
|
26
|
+
Dynamic: summary
|
27
|
+
|
28
|
+
<h1>DAX_UTIL</h1>
|
29
|
+
|
30
|
+
## **Biblioteca de funcionalidades**
|
31
|
+
|
32
|
+
## Conteudo
|
33
|
+
|
34
|
+
Os pacotes que compoem esta biblioteca sao:<br>
|
35
|
+
- Cipher<br>
|
36
|
+
- DateUtils<br>
|
37
|
+
- Generic<br>
|
38
|
+
- SQL<br>
|
39
|
+
- System<br>
|
40
|
+
- WebHook<br>
|
41
|
+
|
42
|
+
<h3>Descricao dos pacotes...</h3>
|
43
|
+
<h2>Cipher:</h2>
|
44
|
+
|
45
|
+
Pacote responsavel por criptografar e descriptografar conteudos, composta
|
46
|
+
por tres classes: RSA, AES e B64.
|
47
|
+
Peculiaridades de cada uma destas classes:<br>
|
48
|
+
- <b>RSA</b>: Criptografa textos curtos
|
49
|
+
- <b>AES</b>: Criptografa textos longos (faz uso tambem da RSA)
|
50
|
+
- <b>B64</b>: Criptografia mais vulneravel
|
51
|
+
|
52
|
+
<b><u>from Utils.Cipher import RSA, AES, B64</b></u>
|
53
|
+
|
54
|
+
Apesar de criptografar qualquer tipo de valor, nao e recomendada utilizar
|
55
|
+
para senhas ou informacoes sensiveis pois sua vulnerabilidade e grande.<br>
|
56
|
+
***Em breve sera disponibilizadas funcionalidades para este fim neste pacote
|
57
|
+
|
58
|
+
<h2>DateUtils</h2> Pacote responsavel por manipulacao de datas e horas
|
59
|
+
<h2>Generic</h2>Funcionalidades de utilizacao generica. Principal foco e facilitar e
|
60
|
+
diminuir aqueles codigos que ocupam varias linhas suprimindo-os em apenas uma linha,
|
61
|
+
quando possivel. Ex.:<br>
|
62
|
+
- NVL() --> Equivalente ao NVL do ORACLE. nvl(None, "a")<br>
|
63
|
+
- IIF() --> If de uma linha so IF(value_boolean, value_True, value_False)<br>
|
64
|
+
- entre outras funconalidades<br>
|
65
|
+
|
66
|
+
<h2>SQL</h2>Ainda em desenvolvimento. Com objetivo de facilitar obtencao de valores de cursores, etc.
|
67
|
+
<h2>System</h2>Obtem informacoes do sistema operacional
|
68
|
+
<h2>WebHook</h2>Funcionalidades para conversar com TEAMS e SLACK
|
@@ -0,0 +1,55 @@
|
|
1
|
+
LICENCE
|
2
|
+
README.md
|
3
|
+
setup.py
|
4
|
+
DE_LIB.egg-info/PKG-INFO
|
5
|
+
DE_LIB.egg-info/SOURCES.txt
|
6
|
+
DE_LIB.egg-info/dependency_links.txt
|
7
|
+
DE_LIB.egg-info/requires.txt
|
8
|
+
DE_LIB.egg-info/top_level.txt
|
9
|
+
DE_Lib/__init__.py
|
10
|
+
DE_Lib.egg-info/PKG-INFO
|
11
|
+
DE_Lib.egg-info/SOURCES.txt
|
12
|
+
DE_Lib.egg-info/dependency_links.txt
|
13
|
+
DE_Lib.egg-info/requires.txt
|
14
|
+
DE_Lib.egg-info/top_level.txt
|
15
|
+
DE_Lib/Cloud/__init__.py
|
16
|
+
DE_Lib/DataBase/Azure.py
|
17
|
+
DE_Lib/DataBase/Cache.py
|
18
|
+
DE_Lib/DataBase/Firebird.py
|
19
|
+
DE_Lib/DataBase/Informix.py
|
20
|
+
DE_Lib/DataBase/Metadata.py
|
21
|
+
DE_Lib/DataBase/MsSql.py
|
22
|
+
DE_Lib/DataBase/MySql.py
|
23
|
+
DE_Lib/DataBase/Oracle.py
|
24
|
+
DE_Lib/DataBase/Postgres.py
|
25
|
+
DE_Lib/DataBase/RedShift.py
|
26
|
+
DE_Lib/DataBase/SQCipher.py
|
27
|
+
DE_Lib/DataBase/SQLite.py
|
28
|
+
DE_Lib/DataBase/__init__.py
|
29
|
+
DE_Lib/Files/Avro.py
|
30
|
+
DE_Lib/Files/Csv.py
|
31
|
+
DE_Lib/Files/JSon.py
|
32
|
+
DE_Lib/Files/Parquet.py
|
33
|
+
DE_Lib/Files/Txt.py
|
34
|
+
DE_Lib/Files/Xlsx.py
|
35
|
+
DE_Lib/Files/__init__.py
|
36
|
+
DE_Lib/Log/DE_LogEventos.py
|
37
|
+
DE_Lib/Log/Level.py
|
38
|
+
DE_Lib/Log/Log.py
|
39
|
+
DE_Lib/Log/__init__.py
|
40
|
+
DE_Lib/Utils/Colors.py
|
41
|
+
DE_Lib/Utils/DateUtils.py
|
42
|
+
DE_Lib/Utils/Generic.py
|
43
|
+
DE_Lib/Utils/SQL.py
|
44
|
+
DE_Lib/Utils/System.py
|
45
|
+
DE_Lib/Utils/WebHook.py
|
46
|
+
DE_Lib/Utils/__init__.py
|
47
|
+
DE_Lib/Utils/Cipher/Aes.py
|
48
|
+
DE_Lib/Utils/Cipher/Argon.py
|
49
|
+
DE_Lib/Utils/Cipher/Base64.py
|
50
|
+
DE_Lib/Utils/Cipher/Cipher.py
|
51
|
+
DE_Lib/Utils/Cipher/Fernet.py
|
52
|
+
DE_Lib/Utils/Cipher/Gcm.py
|
53
|
+
DE_Lib/Utils/Cipher/Pbkdf2.py
|
54
|
+
DE_Lib/Utils/Cipher/Rsa.py
|
55
|
+
DE_Lib/Utils/Cipher/__init__.py
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
DE_Lib
|
File without changes
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import redshift_connector as DB
|
2
|
+
|
3
|
+
|
4
|
+
class Azure:
|
5
|
+
def __init__(self):
|
6
|
+
self._connection_is_valid = None
|
7
|
+
self._nome_database = None
|
8
|
+
self._cnn = None
|
9
|
+
self.__database_error = None
|
10
|
+
|
11
|
+
def AZURE(self, string_connect: dict):
|
12
|
+
conn = None
|
13
|
+
try:
|
14
|
+
from azure.storage.filedatalake import DataLakeServiceClient as az
|
15
|
+
|
16
|
+
conn = az.connect(host=string_connect["host"],
|
17
|
+
database=string_connect["instance"],
|
18
|
+
user=string_connect["username"],
|
19
|
+
password=string_connect["password"]
|
20
|
+
)
|
21
|
+
self._connection_is_valid = True
|
22
|
+
self._nome_database = string_connect["database"]
|
23
|
+
except Exception as error:
|
24
|
+
self._connection_is_valid = False
|
25
|
+
self.__database_error = conn.DatabaseError
|
26
|
+
conn = error
|
27
|
+
finally:
|
28
|
+
return conn
|
29
|
+
|
30
|
+
@property
|
31
|
+
def CONNECTION(self):
|
32
|
+
return self._cnn
|
33
|
+
|
34
|
+
@property
|
35
|
+
def CONNECTION_VALID(self):
|
36
|
+
return self._connection_is_valid
|
37
|
+
|
38
|
+
@property
|
39
|
+
def NOME_DATABASE(self):
|
40
|
+
return self._nome_database.upper()
|
41
|
+
|
42
|
+
@property
|
43
|
+
def DATABASE_ERROR(self):
|
44
|
+
return self.__database_error
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import jaydebeapi as jdb
|
2
|
+
import jpype as jp
|
3
|
+
import os
|
4
|
+
import json
|
5
|
+
|
6
|
+
class Cache:
|
7
|
+
def __init__(self):
|
8
|
+
self._connection_is_valid = None
|
9
|
+
self._nome_database = None
|
10
|
+
self._cnn = None
|
11
|
+
self.__database_error = None
|
12
|
+
|
13
|
+
def Connect(self, string_connect):
|
14
|
+
"""
|
15
|
+
Conexao com a base CACHÉ (Intersystem)
|
16
|
+
O arquivo "CacheDB.jar" --> Tem que estar na mesma pasta de da lib ou ter o seu
|
17
|
+
caminho completo declarado na chamada da funcao
|
18
|
+
:param string_connect:
|
19
|
+
"database": "cache",
|
20
|
+
"name_conection": "Nome da conexão para melhor identicacao",
|
21
|
+
"driver": str: default = "CacheDB.jar",
|
22
|
+
"user": str: Nome do usuario,
|
23
|
+
"pwd": str: senha do usuario,
|
24
|
+
"host": str: Nome do host (Url ou IP),
|
25
|
+
"port": str: Numero da porta --> default = "1972",
|
26
|
+
"instance": str: <Nome da instanciaa ser conectada>
|
27
|
+
:return:
|
28
|
+
"""
|
29
|
+
msg, result = None, None
|
30
|
+
try:
|
31
|
+
if string_connect["database"] == "":
|
32
|
+
string_connect["database"] = "cache"
|
33
|
+
if string_connect["driver_conexao"] == "":
|
34
|
+
string_connect["driver_conexao"] = "CacheDB.jar"
|
35
|
+
if string_connect["port"] == "":
|
36
|
+
string_connect["port"] = "1972"
|
37
|
+
jarODBC = os.path.join(string_connect["driver_library"], string_connect["driver_conexao"])
|
38
|
+
JHOME = jp.getDefaultJVMPath()
|
39
|
+
jp.startJVM(JHOME, f"""-Djava.class.path={jarODBC}""")
|
40
|
+
__driver = "com.intersys.jdbc.CacheDriver"
|
41
|
+
__usr = string_connect["user"]
|
42
|
+
__pwd = string_connect["pwd"]
|
43
|
+
__host = string_connect["host"]
|
44
|
+
__port = string_connect["port"]
|
45
|
+
__namespace = string_connect["instance"]
|
46
|
+
__url = f"""jdbc:Cache://{__host}:{__port}/{__namespace}"""
|
47
|
+
result = jdb.connect(__driver, __url, [__usr, __pwd])
|
48
|
+
self._connection_is_valid = True
|
49
|
+
self._cnn = result
|
50
|
+
self._database_error = f"""{json.dumps(string_connect, indent=4).replace(string_connect["pwd"], "******")}\nConexao bem sucedida!"""
|
51
|
+
self._nome_database = string_connect["database"]
|
52
|
+
except Exception as error:
|
53
|
+
msg = f"""{json.dumps(string_connect, indent=4).replace(string_connect["pwd"], "******")}\nFalha ao tentar se conectar com o banco de dados CACHÉ (intersystem)\nException Error: {error} """
|
54
|
+
result = msg
|
55
|
+
self._connection_is_valid = False
|
56
|
+
self._database_error = msg
|
57
|
+
finally:
|
58
|
+
return result
|
59
|
+
|
60
|
+
@property
|
61
|
+
def CONNECTION(self):
|
62
|
+
return self._cnn
|
63
|
+
|
64
|
+
@property
|
65
|
+
def CONNECTION_VALID(self):
|
66
|
+
return self._connection_is_valid
|
67
|
+
|
68
|
+
@property
|
69
|
+
def NOME_DATABASE(self):
|
70
|
+
return self._nome_database.upper()
|
71
|
+
|
72
|
+
@property
|
73
|
+
def DATABASE_ERROR(self):
|
74
|
+
return self._database_error
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import fbd
|
2
|
+
|
3
|
+
class Firebird:
|
4
|
+
def __init__(self):
|
5
|
+
self._connection_is_valid = None
|
6
|
+
self._nome_database = None
|
7
|
+
self._cnn = None
|
8
|
+
self.__database_error = None
|
9
|
+
|
10
|
+
# ----------------------------------------------------------------
|
11
|
+
# Falta driver - maquina local não permite
|
12
|
+
def Connect(self, string_connect: dict):
|
13
|
+
msg, conn = None, None
|
14
|
+
try:
|
15
|
+
user = string_connect["username"]
|
16
|
+
pwd = string_connect["password"]
|
17
|
+
host = string_connect["host"]
|
18
|
+
port = string_connect["port"]
|
19
|
+
instance = string_connect["instance"]
|
20
|
+
conn = fbd.connect(host=host, database=instance, user=user, password=pwd, port=port)
|
21
|
+
self._connection_is_valid = True
|
22
|
+
self._nome_database = string_connect["database"]
|
23
|
+
self._cnn = conn
|
24
|
+
except Exception as error:
|
25
|
+
conn = error
|
26
|
+
self._connection_is_valid = False
|
27
|
+
self._DATABASE_ERROR = conn.DatabaseError
|
28
|
+
finally:
|
29
|
+
return conn
|
30
|
+
|
31
|
+
@property
|
32
|
+
def CONNECTION(self):
|
33
|
+
return self._cnn
|
34
|
+
|
35
|
+
@property
|
36
|
+
def CONNECTION_VALID(self):
|
37
|
+
return self._connection_is_valid
|
38
|
+
|
39
|
+
@property
|
40
|
+
def NOME_DATABASE(self):
|
41
|
+
return self._nome_database.upper()
|
42
|
+
|
43
|
+
@property
|
44
|
+
def DATABASE_ERROR(self):
|
45
|
+
return self._DATABASE_ERROR
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class Informix:
|
4
|
+
def __init__(self):
|
5
|
+
self._connection_is_valid = None
|
6
|
+
self._nome_database = None
|
7
|
+
self._cnn = None
|
8
|
+
self.__database_error = None
|
9
|
+
|
10
|
+
# ----------------------------------------------------------------
|
11
|
+
# Falta tudo (Instalar driver ODBC) Maquina local não permite
|
12
|
+
def Connect(self, string_connect: dict):
|
13
|
+
try:
|
14
|
+
pass
|
15
|
+
self._connection_is_valid = True
|
16
|
+
self._cnn = None
|
17
|
+
except Exception as error:
|
18
|
+
self._connection_is_valid = False
|
19
|
+
self._DATABASE_ERROR = True
|
20
|
+
finally:
|
21
|
+
pass
|
22
|
+
|
23
|
+
@property
|
24
|
+
def CONNECTION(self):
|
25
|
+
return self._cnn
|
26
|
+
|
27
|
+
@property
|
28
|
+
def CONNECTION_VALID(self):
|
29
|
+
return self._connection_is_valid
|
30
|
+
|
31
|
+
@property
|
32
|
+
def NOME_DATABASE(self):
|
33
|
+
return self._nome_database.upper()
|
34
|
+
|
35
|
+
@property
|
36
|
+
def DATABASE_ERROR(self):
|
37
|
+
return self.__database_error
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import pandas as pd
|
2
|
+
|
3
|
+
class Metadata:
|
4
|
+
def __init__(self):
|
5
|
+
...
|
6
|
+
|
7
|
+
def getMetadados(self, table, owner: str = '', con=None, database: str = 'ORACLE', driver: str = "SQLALCHEMY"):
|
8
|
+
msg, result = None, None
|
9
|
+
try:
|
10
|
+
self._owner = owner
|
11
|
+
self._table = table
|
12
|
+
self._qry = self.QUERYS_METADADOS[database.upper()]
|
13
|
+
#cur = con.connection.cursor()
|
14
|
+
if driver.upper() == "SQLALCHEMY":
|
15
|
+
result = pd.read_sql(con=con.connection, sql=self.QUERY)
|
16
|
+
else:
|
17
|
+
result = pd.read_sql(con=con, sql=self.QUERY)
|
18
|
+
except Exception as error:
|
19
|
+
msg = error
|
20
|
+
result = msg
|
21
|
+
finally:
|
22
|
+
return result
|
23
|
+
|
24
|
+
@property
|
25
|
+
def QUERYS_METADADOS(self):
|
26
|
+
value = {
|
27
|
+
"ORACLE": f"""Select * from all_tab_columns where owner = '{self._owner}' and table_name = '{self._table}' order by column_id"""
|
28
|
+
,
|
29
|
+
"POSTGRES": f"""Select * from information_schema.columns where table_schema = '{self._owner}' and table_name = '{self._table}' order by ordinal_position"""
|
30
|
+
, "SQLITE": f"""Select * from pragma_table_info('{self._table}') order by cid"""
|
31
|
+
,
|
32
|
+
"MYSQL": f"""Select * from information_schema.columns where table_name = '{self._table}' order by ordinal_position"""
|
33
|
+
,
|
34
|
+
"REDSHIFT": f"""Select column_name from information_schema.columns where table_schema ='{self._owner}' and table_name = '{self._table}' order by ordinal_position"""
|
35
|
+
,
|
36
|
+
"CACHE": f"""SELECT * FROM INFORMATION_SCHEMA.COLUMNS where table_schema = '{self._owner}' and table_name = '{self._table}' order by ordinal_position"""
|
37
|
+
, "MSSQL": f"""select t.name Tabela
|
38
|
+
,ac.name Coluna
|
39
|
+
,ac.column_id
|
40
|
+
,sep.value Comment
|
41
|
+
,t2.name Data_Type
|
42
|
+
from sys.schemas s
|
43
|
+
join sys.tables t
|
44
|
+
on t.schema_id = s.schema_id
|
45
|
+
join sys.all_columns ac
|
46
|
+
on ac.object_id = t.object_id
|
47
|
+
join sys.types t2
|
48
|
+
on t2.system_type_id = ac.system_type_id
|
49
|
+
left join sys.extended_properties sep
|
50
|
+
on sep.major_id = t.object_id
|
51
|
+
and sep.minor_id = ac.column_id
|
52
|
+
and sep.name = 'MS_Description'
|
53
|
+
where s.name = ISNULL('{self._owner}', 'dbo')
|
54
|
+
and t.name = '{self._table}'
|
55
|
+
order by t.name, ac.column_id
|
56
|
+
"""
|
57
|
+
}
|
58
|
+
return value
|
59
|
+
|
60
|
+
@property
|
61
|
+
def QUERY(self):
|
62
|
+
return self._qry
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import pymssql as mssql
|
2
|
+
|
3
|
+
class MsSql:
|
4
|
+
def __init__(self):
|
5
|
+
self._connection_is_valid = None
|
6
|
+
self._nome_database = None
|
7
|
+
self._cnn = None
|
8
|
+
self.__database_error = None
|
9
|
+
|
10
|
+
def Connect(self, string_connect: dict):
|
11
|
+
msg, conn = None, None
|
12
|
+
try:
|
13
|
+
# Efetuando a conexao com a instancia do BANCO
|
14
|
+
conn = mssql.connect(user=string_connect["username"], password=string_connect["password"], database=string_connect["instance"], server=string_connect["host"])
|
15
|
+
self._connection_is_valid = True
|
16
|
+
self._nome_database = string_connect["database"]
|
17
|
+
self._cnn = conn
|
18
|
+
except Exception as error:
|
19
|
+
conn = error
|
20
|
+
self._connection_is_valid = False
|
21
|
+
self._DATABASE_ERROR = conn.DatabaseError
|
22
|
+
finally:
|
23
|
+
return conn
|
24
|
+
|
25
|
+
@property
|
26
|
+
def CONNECTION(self):
|
27
|
+
return self._cnn
|
28
|
+
|
29
|
+
@property
|
30
|
+
def CONNECTION_VALID(self):
|
31
|
+
return self._connection_is_valid
|
32
|
+
|
33
|
+
@property
|
34
|
+
def NOME_DATABASE(self):
|
35
|
+
return self._nome_database.upper()
|
36
|
+
|
37
|
+
@property
|
38
|
+
def DATABASE_ERROR(self):
|
39
|
+
return self._DATABASE_ERROR
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import mysql.connector as mysql
|
2
|
+
import json
|
3
|
+
|
4
|
+
class MySql:
|
5
|
+
def __init__(self):
|
6
|
+
self._connection_is_valid = None
|
7
|
+
self._nome_database = None
|
8
|
+
self._cnn = None
|
9
|
+
self.__database_error = None
|
10
|
+
|
11
|
+
def Connect(self, string_connect: dict):
|
12
|
+
msg, conn = None, None
|
13
|
+
try:
|
14
|
+
# Efetuando a conexao com a instancia do BANCO
|
15
|
+
result = mysql.connect(user=string_connect["username"], password=string_connect["password"], database=string_connect["instance"], host=string_connect["host"])
|
16
|
+
self._connection_is_valid = True
|
17
|
+
self._cnn = result
|
18
|
+
self._DATABASE_ERROR = f"""{json.dumps(string_connect, indent=4).replace(string_connect["password"], "******")}\nConexao bem sucedida!"""
|
19
|
+
self._nome_database = string_connect["database"]
|
20
|
+
except Exception as error:
|
21
|
+
msg = f"""{json.dumps(string_connect, indent=4).replace(string_connect["password"], "******")}\nFalha ao tentar se conectar com o banco de dados MYSQL\nException Error: {error} """
|
22
|
+
result = msg
|
23
|
+
self._connection_is_valid = False
|
24
|
+
self._DATABASE_ERROR = msg
|
25
|
+
finally:
|
26
|
+
return result
|
27
|
+
|
28
|
+
@property
|
29
|
+
def CONNECTION(self):
|
30
|
+
return self._cnn
|
31
|
+
|
32
|
+
@property
|
33
|
+
def CONNECTION_VALID(self):
|
34
|
+
return self._connection_is_valid
|
35
|
+
|
36
|
+
@property
|
37
|
+
def NOME_DATABASE(self):
|
38
|
+
return self._nome_database.upper()
|
39
|
+
|
40
|
+
@property
|
41
|
+
def DATABASE_ERROR(self):
|
42
|
+
return self._DATABASE_ERROR
|
@@ -0,0 +1,111 @@
|
|
1
|
+
import os
|
2
|
+
import cx_Oracle as ora
|
3
|
+
import sqlalchemy as sqa
|
4
|
+
import json
|
5
|
+
|
6
|
+
class Oracle:
|
7
|
+
def __init__(self):
|
8
|
+
self._connection_is_valid = None
|
9
|
+
self._nome_database = None
|
10
|
+
self._cnn = None
|
11
|
+
self.__database_error = None
|
12
|
+
|
13
|
+
def Connect_ORA(self, string_connect: dict):
|
14
|
+
pathlib, msg, result = None, None, None
|
15
|
+
try:
|
16
|
+
# Definindo a Library ORACLE
|
17
|
+
if "library" in string_connect.keys():
|
18
|
+
if string_connect["library"] is None:
|
19
|
+
pathlib = os.getenv("ORACLE_LIB")
|
20
|
+
else:
|
21
|
+
pathlib = string_connect["library"]
|
22
|
+
else:
|
23
|
+
pathlib = os.getenv("ORACLE_LIB")
|
24
|
+
|
25
|
+
# Consistindo se a biblioteca do oracle ja esta iniciada
|
26
|
+
try:
|
27
|
+
ora.init_oracle_client(lib_dir=pathlib)
|
28
|
+
except:
|
29
|
+
pass
|
30
|
+
# não faz nada (e para deixar assim se nao da erro)
|
31
|
+
|
32
|
+
# Definindo o tipo de instancia SID/SERVICE_NAME
|
33
|
+
if string_connect["type_conection"].upper() == "SID":
|
34
|
+
dnsName = ora.makedsn(host=string_connect["host"], port=string_connect["port"], sid=string_connect["instance"])
|
35
|
+
else:
|
36
|
+
dnsName = ora.makedsn(host=string_connect["host"], port=string_connect["port"], service_name=string_connect["instance"])
|
37
|
+
|
38
|
+
# Efetuando a conexao com a instancia do BANCO
|
39
|
+
result = ora.connect(string_connect["username"], string_connect["password"], dnsName, threaded=True)
|
40
|
+
self._connection_is_valid = True
|
41
|
+
self._nome_database = string_connect["database"]
|
42
|
+
self._cnn = result
|
43
|
+
self.__database_error = f"""{json.dumps(string_connect, indent=4).replace(string_connect["password"], "******")}\nConexao bem sucedida!"""
|
44
|
+
except Exception as error:
|
45
|
+
msg = f"""{json.dumps(string_connect, indent=4).replace(string_connect["password"], "******")}\nFalha ao tentar se conectar com o banco de dados ORACLE\nException Error: {error} """
|
46
|
+
result = msg
|
47
|
+
self._connection_is_valid = False
|
48
|
+
self.__database_error = msg
|
49
|
+
|
50
|
+
finally:
|
51
|
+
return result
|
52
|
+
|
53
|
+
def Connect_SQLA(self, string_connect: dict):
|
54
|
+
conn = None
|
55
|
+
try:
|
56
|
+
# Definindo a Library ORACLE
|
57
|
+
if string_connect["path_library"] is None:
|
58
|
+
pathlib = os.getenv("ORACLE_LIB")
|
59
|
+
else:
|
60
|
+
pathlib = string_connect["path_library"]
|
61
|
+
|
62
|
+
# Consistindo se a biblioteca do oracle ja esta iniciada
|
63
|
+
try:
|
64
|
+
ora.init_oracle_client(lib_dir=pathlib)
|
65
|
+
except:
|
66
|
+
pass
|
67
|
+
# não faz nada (e para deixar assim se nao da erro)
|
68
|
+
# Validando se foi passado um driver para conexao
|
69
|
+
if string_connect["driver_conexao"] is None:
|
70
|
+
string_connect["driver_conexao"] = "cx_oracle"
|
71
|
+
database = string_connect["database"]
|
72
|
+
driver = string_connect["driver_conexao"]
|
73
|
+
user = string_connect["username"]
|
74
|
+
pwd = string_connect["password"]
|
75
|
+
host = string_connect["host"]
|
76
|
+
port = string_connect["port"]
|
77
|
+
string_connect["instance"] = ora.makedsn(host, port, string_connect["instance"])
|
78
|
+
# Validando o tipo de conexao (SID ou SERVICE_NAME) apenas oracle
|
79
|
+
if string_connect["type_conection"].upper() == "SERVICE_NAME":
|
80
|
+
string_connect["instance"] = string_connect["instance"].replace("SID", "SERVICE_NAME")
|
81
|
+
dnsName = string_connect["instance"]
|
82
|
+
str_cnn = f"""{database.lower()}{driver}://{user}:{pwd}@{dnsName}"""
|
83
|
+
engine = sqa.create_engine(str_cnn)
|
84
|
+
result = engine.connect()
|
85
|
+
self._connection_is_valid = True
|
86
|
+
self._cnn = result
|
87
|
+
self.__database_error = f"""{json.dumps(string_connect, indent=4).replace(string_connect["password"], "******")}\nConexao bem sucedida!"""
|
88
|
+
self._nome_database = string_connect["database"]
|
89
|
+
except Exception as error:
|
90
|
+
msg = f"""{json.dumps(string_connect, indent=4).replace(string_connect["password"], "******")}\nFalha ao tentar se conectar com o banco de dados ORACLE (SqlAlchemy)\nException Error: {error} """
|
91
|
+
result = msg
|
92
|
+
self._connection_is_valid = False
|
93
|
+
self.__database_error = msg
|
94
|
+
finally:
|
95
|
+
return result
|
96
|
+
|
97
|
+
@property
|
98
|
+
def CONNECTION(self):
|
99
|
+
return self._cnn
|
100
|
+
|
101
|
+
@property
|
102
|
+
def CONNECTION_VALID(self):
|
103
|
+
return self._connection_is_valid
|
104
|
+
|
105
|
+
@property
|
106
|
+
def NOME_DATABASE(self):
|
107
|
+
return self._nome_database.upper()
|
108
|
+
|
109
|
+
@property
|
110
|
+
def DATABASE_ERROR(self):
|
111
|
+
return self.__database_error
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import psycopg2 as ps2
|
2
|
+
|
3
|
+
class Postgres:
|
4
|
+
def __init__(self):
|
5
|
+
self._connection_is_valid = None
|
6
|
+
self._nome_database = None
|
7
|
+
self._cnn = None
|
8
|
+
self.__database_error = None
|
9
|
+
|
10
|
+
def Connect(self, string_connect: dict):
|
11
|
+
msg, conn = None, None
|
12
|
+
try:
|
13
|
+
# Efetuando a conexao com a instancia do BANCO
|
14
|
+
conn = ps2.connect(user=string_connect["username"], password=string_connect["password"], database=string_connect["instance"], host=string_connect["host"])
|
15
|
+
self._connection_is_valid = True
|
16
|
+
self._nome_database = string_connect["database"]
|
17
|
+
self._cnn = conn
|
18
|
+
except Exception as error:
|
19
|
+
conn = f"""Falha ao tentar se conectar com o banco de dados POSTGRES.\n """
|
20
|
+
self._connection_is_valid = False
|
21
|
+
self._DATABASE_ERROR = conn.DatabaseError
|
22
|
+
finally:
|
23
|
+
return conn
|
24
|
+
|
25
|
+
@property
|
26
|
+
def CONNECTION(self):
|
27
|
+
return self._cnn
|
28
|
+
|
29
|
+
@property
|
30
|
+
def CONNECTION_VALID(self):
|
31
|
+
return self._connection_is_valid
|
32
|
+
|
33
|
+
@property
|
34
|
+
def NOME_DATABASE(self):
|
35
|
+
return self._nome_database.upper()
|
36
|
+
|
37
|
+
@property
|
38
|
+
def DATABASE_ERROR(self):
|
39
|
+
return self.__database_error
|