Skip to content

Instantly share code, notes, and snippets.

@dario61081
Created July 6, 2023 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dario61081/8da5d839b9d5a691fcd166488f152658 to your computer and use it in GitHub Desktop.
Save dario61081/8da5d839b9d5a691fcd166488f152658 to your computer and use it in GitHub Desktop.
Clase conexion con base de datos
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