ぼざろクリーチャーシリーズ DB 兼 API(自分用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

my_eloquent.py 709 B

1 month ago
1 month ago
1 month ago
12345678910111213141516171819202122232425262728293031
  1. # pylint: disable = missing-class-docstring
  2. # pylint: disable = missing-function-docstring
  3. """
  4. みてるぞ式魔改造(言ふほどか?)版 Eloquent
  5. """
  6. import eloquent
  7. class DatabaseManager (eloquent.DatabaseManager):
  8. pass
  9. class Model (eloquent.Model):
  10. id: int
  11. def upsert (
  12. self,
  13. *args: str,
  14. ) -> None:
  15. q = self.query ()
  16. for arg in args:
  17. q = q.where (arg, getattr (self, arg))
  18. row = q.first ()
  19. if row is not None:
  20. self.id = row.id
  21. # pylint: disable = invalid-name
  22. # pylint: disable = attribute-defined-outside-init
  23. self._Model__exists = True
  24. self.save ()