I’m currently developing a project that requires an effective way to implement a repository pattern handler. However, I’m feeling a bit lost regarding the optimal structure for the code and the necessary methods that should be incorporated into the handler class.
Here’s my current attempt:
class Repository:
def __init__(self, db_connection):
self.db = db_connection
def get_user(self, id):
sql = "SELECT * FROM users WHERE id = ?"
return self.db.execute(sql, id)
def create_user(self, user_info):
sql = "INSERT INTO users (name, email) VALUES (?, ?)"
return self.db.execute(sql, user_info['name'], user_info['email'])
Am I on the right track with this repository approach? Are there any additional methods I should consider or should I modify the current structure? Any insights would be greatly appreciated.