-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
35 lines (26 loc) · 896 Bytes
/
database.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
31
32
33
34
35
class Database:
def __init__(self):
self.connection = None
self.host = None
self.port = None
self.username = None
self.password = None
self.database_name = None
def connect(self):
if self.connection is not None:
raise ValueError("Already connected")
# Connect to the database using the configured parameters
# ...
self.connection = ... # store the connection object
def disconnect(self):
if self.connection is None:
raise ValueError("Not connected")
# Disconnect from the database
# ...
self.connection = None
def execute_query(self, query):
if self.connection is None:
raise ValueError("Not connected")
# Execute the given query on the database and return the result
# ...
# return result