-
Notifications
You must be signed in to change notification settings - Fork 0
/
conexao.py
30 lines (25 loc) · 858 Bytes
/
conexao.py
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
30
from abc import ABC, abstractmethod
from sqlalchemy import create_engine
import urllib.parse
class Conexao(ABC):
@abstractmethod
def get_engine(self):
pass
class ConexaoSingleton(Conexao):
_instance = None
_engine = None
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(ConexaoSingleton, cls).__new__(cls, *args, **kwargs)
cls._engine = cls._create_engine()
return cls._instance
@staticmethod
def _create_engine():
user = 'root'
password = urllib.parse.quote_plus('senai@123')
host = 'localhost'
database = 'flashtrainer'
connection_string = f'mysql+pymysql://{user}:{password}@{host}/{database}'
return create_engine(connection_string)
def get_engine(self):
return self._engine