I'm currently working on a project that requires using a database. This system may be required to use an SQL database in the future, but for now we are using Google Spreadsheets via API because we need to access the data quickly, easily and for free.

My question is: Should we create a DB API in case we change the database backend? As I said in the future is possible that we use SQL, so I was thinking about using and API to change just the DB server, and not the whole app.

How you do this? Do you create an API once and use it while the DB server changes? Do you change the whole app when you need a different DB?


  • which programming language do you use? – k3b Mar 22 '17 at 13:58
  • Currently using Python in this project (Flask mainly, began as a small project) – aaossa Mar 23 '17 at 0:13

Use a Database-Abstraction-Layer (DBAL). Running SQL against a Google Spreadsheet will not be easy; so you should put your abstraction further up the hierarchy.

I'd suggest the Repository pattern. Create implementations that work with the Spreadsheet API. When you later switch to a SQL server, create implementations that utilize an O/RM.

  • Thanks for your suggestion. So I could expose an API to this repository, which calls the data from Spreadsheets, and if I change the database (for instance, to SQL) I can use the same API but the repository implementation will change (and the new DB). Is this what you meant? (I'll keep reading about this) – aaossa Mar 23 '17 at 0:36
  • Exactly. You'll swap GoogleDocsRepository for e.g. SQLRepository in your DI config – marstato Mar 23 '17 at 7:16
  • Nice, I really liked this approach. It's nice to see that one of the solutions I though was a pattern. Thanks @marstato – aaossa Mar 23 '17 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.