Refactored SQLite backend to help support custom queries