def _target2stmts(self, basestmt: Select, target: Target) -> List[Select]:
        """Return a list of selection statements for the different infrastructure queries."""

        basestmts: List[Select] = []

        if not target.name:
            return basestmts

        # the first scripts we need are the ones matching only the infrastructure,
        # but which do not contain any storage_class condition
        basestmts += [
            basestmt.filter(db.Script.conditions["infrastructure"]
                            ["name"].as_string() == target.name).filter(
                                db.Script.conditions["infrastructure"]
                                ["storage_class"] == JSON.NULL)
        ]

        # Now we need a lookup for the given infrastructure.
        # If not found or no storage spec (atm still possible unfortunately), we're done
        try:
            istorage = self._driver.select_sql(
                select(db.Infrastructure.configuration).filter(
                    db.Infrastructure.name == target.name).filter(
                        db.Infrastructure.configuration["storage"].isnot(
                            {})))[0][0]["storage"]
        except (KeyError, IndexError):
            return basestmts

        # now extract the available storage class definitions and build other queries matching them
        storage_classes = [
            config["storage_class"] for _, config in istorage.items()
        ]

        basestmts.append(
            basestmt.filter(
                db.Script.conditions["infrastructure"]["name"] ==
                JSON.NULL).filter(
                    db.Script.conditions["infrastructure"]
                    ["storage_class"].as_string().in_(storage_classes)))

        basestmts.append(
            basestmt.filter(db.Script.conditions["infrastructure"]
                            ["name"].as_string() == target.name).filter(
                                db.Script.conditions["infrastructure"]
                                ["storage_class"] == JSON.NULL))

        basestmts.append(
            basestmt.filter(
                db.Script.conditions["infrastructure"]["name"].as_string() ==
                target.name).filter(
                    db.Script.conditions["infrastructure"]
                    ["storage_class"].as_string().in_(storage_classes)))

        return basestmts
    def _opts2stmts(basestmt: Select, opts: List[str]) -> List[Select]:
        stmts = []

        for opt in opts:
            if "version" in opt:
                logger.info("Ignore version as a optimisation")
                continue

            opt_key, opt_value = opt.split(":")

            # "unparse" the options again to be able to use them to query
            # directly the features in Script
            if opt_value.lower() == "true":
                stmts.append(
                    basestmt.filter(
                        db.Script.conditions["application"]["feature"]
                        [opt_key].as_boolean() == True  # noqa: E712
                    ))
            elif opt_value.lower() == "false":
                stmts.append(
                    basestmt.filter(
                        db.Script.conditions["application"]["feature"]
                        [opt_key].as_boolean() == False  # noqa: E712
                    ))
            else:
                try:
                    stmts.append(
                        basestmt.filter(
                            db.Script.conditions["application"]["feature"]
                            [opt_key].as_integer() == int(opt_value)))
                except ValueError:
                    stmts.append(
                        basestmt.filter(
                            db.Script.conditions["application"]["feature"]
                            [opt_key].as_string() == opt_value))

        return stmts