Query builder implementation