Implement a rough database query function