Effect after implementation: 1. Safe. Interface information encapsulation is convenient for confidential management; 2. reuse. Disposable packaging, permanent reuse; 3. Get started quickly. It is convenient for students who are not familiar with python and data call and can only use simple sql, saving time and effort.
We take MySQL, MongoDB and Influx DB as examples to define interface methods, and then encapsulate them into 1 general methods.
mysql_get(sql,db):
mongo_get(sql,db):
intrusion _ get(SQL,db):
As you can see, the parameters of the above function call are sql and db. We add another parameter db_type, which will construct a general method to call the above database.
Similarly, other types of databases can be added to this general framework, including but not limited to all types of relational, key-value and time-series databases.