docs: def _unique(session, cls, queryfunc, constructor, arg, kw):
      '''
      https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/UniqueObject
      Checks if ORM entity exists according to criteria,
      if yes, returns it, if no, creates
      '''
      with session.no_autoflush:
          q = session.query(cls)
          q = queryfunc(q, *arg, **kw)
          obj = q.first()
          if not obj:
              obj = constructor(*arg, **kw)
              session.add(obj)
      return obj