|
- # pylint: disable = missing-class-docstring
- # pylint: disable = missing-function-docstring
-
- """
- みてるぞ式魔改造(言ふほどか?)版 Eloquent
- """
-
- import eloquent
-
-
- class DatabaseManager (eloquent.DatabaseManager):
- pass
-
-
- class Model (eloquent.Model):
- id: int
-
- def upsert (
- self,
- *args: str,
- ) -> None:
- q = self.query ()
- for arg in args:
- q = q.where (arg, getattr (self, arg))
- row = q.first ()
- if row is not None:
- self.id = row.id
- # pylint: disable = invalid-name
- # pylint: disable = attribute-defined-outside-init
- self._Model__exists = True
- self.save ()
|