Updates the model, or in case there is no match in database creates a new one. If a pk is supplied but no row exists with that pk, a new row is created with the supplied pk and field values rather than raising ``NoMatch``. :param kwargs: fields names and pr
(self, **kwargs: Any)
| 1238 | raise integrity_error from None |
| 1239 | |
| 1240 | async def update_or_create(self, **kwargs: Any) -> "T": |
| 1241 | """ |
| 1242 | Updates the model, or in case there is no match in database creates a new one. |
| 1243 | |
| 1244 | If a pk is supplied but no row exists with that pk, a new row is |
| 1245 | created with the supplied pk and field values rather than raising |
| 1246 | ``NoMatch``. |
| 1247 | |
| 1248 | :param kwargs: fields names and proper value types |
| 1249 | :type kwargs: Any |
| 1250 | :return: updated or created model |
| 1251 | :rtype: Model |
| 1252 | """ |
| 1253 | pk_name = self.model_config.pkname |
| 1254 | if "pk" in kwargs: |
| 1255 | kwargs[pk_name] = kwargs.pop("pk") |
| 1256 | if pk_name not in kwargs or kwargs.get(pk_name) is None: |
| 1257 | return await self.create(**kwargs) |
| 1258 | try: |
| 1259 | model = await self.get(pk=kwargs[pk_name]) |
| 1260 | except NoMatch: |
| 1261 | return await self.create(**kwargs) |
| 1262 | return await model.update(**kwargs) |
| 1263 | |
| 1264 | async def all(self, *args: Any, **kwargs: Any) -> list["T"]: # noqa: A003 |
| 1265 | """ |