-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.py
More file actions
30 lines (24 loc) · 1 KB
/
Copy pathconnection.py
File metadata and controls
30 lines (24 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from decouple import config
from error_handler import Errores
from pymongo import MongoClient
from pymongo.errors import PyMongoError
import mysql.connector
class Connection:
def __init__(self):
self.error_handle = Errores()
def connection_sql(self):
try:
return mysql.connector.connect(host=config('MYSQL_HOST'),
database=config('MYSQL_BD'),
port=config('MYSQL_PORT'),
user=config('MYSQL_USER'),
password=config('MYSQL_PASSWORD'))
except mysql.connector.Error as err:
self.error_handle.manejar_error(err)
def connection_nosql(self):
try:
cliente = MongoClient(host=config('NOSQL_HOST'),
port=int(config('NOSQL_PORT')))
return cliente
except PyMongoError as err:
self.error_handle.manejar_error(err)