Rewrite the SQL backend to actually work