mardi 3 décembre 2019

What is the best practice of designing a set of database query APIs using Python?

My task is to implement a set of APIs related to database access using Python (mysql.connector). I think of the design patterns to avoid the duplicate codes (e.g., database connection/close). It should behave like @Before and @After in JUnit.

I came up with the Proxy pattern in Java. It uses Java reflection to execute a function before any other function of a class is called. However, how can I implement such dynamic proxy in Python?

I also have questions about the efficiency of this approach. If these APIs are called repeatedly in the upper-layer application, will such frequent connection and disconnection of the database cause inefficiency? If so, what is the better practice?

Aucun commentaire:

Enregistrer un commentaire