yhat / db.py

db.py is an easier way to interact with your databases
BSD 2-Clause "Simplified" License
1.22k stars 111 forks source link

Lazy load database schema #78

Closed rothnic closed 9 years ago

rothnic commented 9 years ago

This commit makes it possible to use DB's query functionality without needing to load the schema information. This helps a lot for databases with a large number of tables that you might interact with, but you also create reusable queries for. If you want to have a one time call to a query, the delay causes by loading the schema dwarfs the time it takes to retrieve the data.

This works by adding table as a property of the DB class. Any time table is called, it checks the private _table property's length. If the length is equal to 0, only then will it call the method to refresh the schema. Otherwise, it just returns _table once it is loaded. This approach limits the affect on the rest of the code.