Created
July 6, 2023 17:04
-
-
Save dario61081/8da5d839b9d5a691fcd166488f152658 to your computer and use it in GitHub Desktop.
Clase conexion con base de datos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Database: | |
def __init__(self, **kwargs): | |
self.username = kwargs.get('username') | |
self.password = kwargs.get('password') | |
self.database = kwargs.get('database') | |
self.host = kwargs.get('host') | |
self.port = kwargs.get('port') | |
self.driver = kwargs.get('driver') | |
self.uri = f"{self.driver}://{self.username}:{self.password}@{self.host}:{self.port}/{self.database}?charset=utf-8" | |
self.engine = create_engine(self.uri) | |
self.connection = self.engine.connect() | |
self.metadata = MetaData(bind=self.engine) | |
self.session = Session(bind=self.connection) | |
def fetch_all(self, query, *args, **kwargs): | |
return self.connection.execute(text(query), *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment