import eloquent class DatabaseManager (eloquent.DatabaseManager): pass class Model (eloquent.Model): 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 self._Model__exists = True # pylint: disable = protected-access self.save ()