Created
July 9, 2024 23:36
-
-
Save WomB0ComB0/70398637153e18b08ca8f9f5feb6b3b6 to your computer and use it in GitHub Desktop.
Arbitrary MySQL database class in Python
This file contains hidden or 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 MySQLDatabase: | |
def __init__(self, database, user, password, host, port): | |
self.database = database | |
self.user = user | |
self.password = password | |
self.host = host | |
self.port = port | |
def connect(self): | |
return MySQLDatabase(self.database, self.user, self.password, self.host, self.port) | |
def disconnect(self): | |
self.database.close() | |
def query(self, query): | |
return self.database.query(query) | |
def execute(self, query): | |
return self.database.execute(query) | |
def fetchone(self, query): | |
return self.database.fetchone(query) | |
def fetchall(self, query): | |
return self.database.fetchall(query) | |
def commit(self): | |
return self.database.commit() | |
def rollback(self): | |
return self.database.rollback() | |
def __str__(self): | |
return f"MySQLDatabase(database={self.database}, user={self.user}, password={self.password}, host={self.host}, port={self.port})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment