[IMP] models: improve query generation for _write() and _store_set_values()