The best way to "Mock a database" is to create a SQLite database on the fly inside your unit tests and test against that. That way whatever code you're using to fetch and post data can be tested against that, should you not want to hit your database directly. As for hitting the real database, this should be part of a larger "Integration Test", where you start all the way at the front end by making a web request and ensuring that your data is fetched/posted properly at the database.
This Dot provides teams with technical leaders who bring deep knowledge of the web platform. We help teams set new standards, and deliver results predictably.
The best way to "Mock a database" is to create a SQLite database on the fly inside your unit tests and test against that. That way whatever code you're using to fetch and post data can be tested against that, should you not want to hit your database directly. As for hitting the real database, this should be part of a larger "Integration Test", where you start all the way at the front end by making a web request and ensuring that your data is fetched/posted properly at the database.
But just remember sometimes if you use an special DB function SQLite won’t be enough.
Great point Oziel