def read(self, index='PRIMARY', mode=None, where=None, limit=None,
             **kwargs):
        if not self.open:
            raise RuntimeError("This handler isn't open yet")

        index_op, index_value = self._parse_index_value(kwargs)

        if index_op is not None and mode is not None:
            raise ValueError("You cannot use an index operator and mode "
                             "together in a handler read")
        elif index_op is None and mode is None:
            # Default
            mode = 'first'

        sql = ["HANDLER {} READ".format(self._handler_name)]
        params = ()

        # Caller's responsibility to ensure the index name is correct
        sql.append("`{}`".format(index))

        if index_op is not None:
            sql.append(index_op)
            if isinstance(index_value, tuple):
                sql.append("(")
                sql.append(",".join("%s" for x in index_value))
                sql.append(")")
                params += index_value
            else:
                sql.append("(%s)")
                params += (index_value,)

        if index_op is None:
            try:
                sql.append(self._read_modes[mode])
            except __HOLE__:
                raise ValueError(
                    "'mode' must be one of: {}"
                    .format(",".join(self._read_modes.keys()))
                )

        if where is None:
            # Use default
            if self._where:
                sql.append(self._where)
                params += self._params
        else:
            # 'where' is another queryset to use the clause from
            if isinstance(where, tuple):
                # Allow parsing in a pre-extracted where clause + params -
                # as iter() does
                where, where_params = where
            else:
                where, where_params = self._extract_where(where)
            sql.append(where)
            params += where_params

        if limit is not None:
            sql.append("LIMIT %s")
            params += (limit,)

        return self._model.objects.using(self.db).raw(" ".join(sql), params)
dataset/ETHPy150Open adamchainz/django-mysql/django_mysql/models/handler.py/Handler.read