ぼざろクリーチャーシリーズ 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.
 
 
 

31 lines
698 B

  1. import eloquent
  2. class DatabaseManager (eloquent.DatabaseManager):
  3. pass
  4. class Model (eloquent.Model):
  5. def upsert (
  6. self,
  7. *args: str,
  8. ) -> None:
  9. q = self.query ()
  10. for arg in args:
  11. q = q.where (arg, getattr (self, arg))
  12. row = q.first ()
  13. if row is not None:
  14. self.id = row.id
  15. self._Model__exists = True # pylint: disable = protected-access
  16. self.save ()
  17. @classmethod
  18. def with_ (
  19. cls,
  20. *relations: str,
  21. ) -> eloquent.QueryBuilder:
  22. q = cls.query ()
  23. for relation in relations:
  24. q = q._load_relation (relation)
  25. return q