| 689 | |
| 690 | @classmethod |
| 691 | def create_query_object(cls, statement, *options, **kwargs): |
| 692 | # lets make a copy of the options, and update with kwargs... |
| 693 | opt = QueryOptions() |
| 694 | # TODO: is it possible that we could have [QueryOptions, QueryOptions, ...]?? |
| 695 | # If so, why??? |
| 696 | opts = list(options) |
| 697 | for o in opts: |
| 698 | if isinstance(o, (QueryOptions, QueryOptionsBase)): |
| 699 | opt = o |
| 700 | opts.remove(o) |
| 701 | args = opt.copy() |
| 702 | args.update(kwargs) |
| 703 | |
| 704 | # now lets get positional parameters. Actual positional |
| 705 | # params OVERRIDE positional_parameters |
| 706 | positional_parameters = args.pop("positional_parameters", []) |
| 707 | if opts and len(opts) > 0: |
| 708 | positional_parameters = opts |
| 709 | |
| 710 | # now the named parameters. NOTE: all the kwargs that are |
| 711 | # not VALID_OPTS must be named parameters, and the kwargs |
| 712 | # OVERRIDE the list of named_parameters |
| 713 | new_keys = list(filter(lambda x: x not in cls._VALID_OPTS, args.keys())) |
| 714 | named_parameters = args.pop("named_parameters", {}) |
| 715 | for k in new_keys: |
| 716 | named_parameters[k] = args[k] |
| 717 | |
| 718 | query = cls(statement, *positional_parameters, **named_parameters) |
| 719 | # now lets try to setup the options. |
| 720 | # but for now we will use the existing N1QLQuery. Could be we can |
| 721 | # add to it, etc... |
| 722 | |
| 723 | # default to false on metrics |
| 724 | query.metrics = args.get("metrics", False) |
| 725 | |
| 726 | for k, v in ((k, args[k]) for k in (args.keys() & cls._VALID_OPTS)): |
| 727 | for target, transform in cls._VALID_OPTS[k].items(): |
| 728 | setattr(query, target, transform(v)) |
| 729 | return query |
| 730 | |
| 731 | |
| 732 | class QueryRequestLogic: |