Return a new :class:`_engine.URL` object with the :attr:`_engine.URL.query` parameter dictionary updated by the given sequence of key/value pairs E.g.:: >>> from sqlalchemy.engine import make_url >>> url = make_url("postgresql+psycopg2://user:pass@ho
(
self,
key_value_pairs: Iterable[Tuple[str, Union[str, List[str]]]],
append: bool = False,
)
| 399 | return self.update_query_pairs(parse_qsl(query_string), append=append) |
| 400 | |
| 401 | def update_query_pairs( |
| 402 | self, |
| 403 | key_value_pairs: Iterable[Tuple[str, Union[str, List[str]]]], |
| 404 | append: bool = False, |
| 405 | ) -> URL: |
| 406 | """Return a new :class:`_engine.URL` object with the |
| 407 | :attr:`_engine.URL.query` |
| 408 | parameter dictionary updated by the given sequence of key/value pairs |
| 409 | |
| 410 | E.g.:: |
| 411 | |
| 412 | >>> from sqlalchemy.engine import make_url |
| 413 | >>> url = make_url("postgresql+psycopg2://user:pass@host/dbname") |
| 414 | >>> url = url.update_query_pairs( |
| 415 | ... [ |
| 416 | ... ("alt_host", "host1"), |
| 417 | ... ("alt_host", "host2"), |
| 418 | ... ("ssl_cipher", "/path/to/crt"), |
| 419 | ... ] |
| 420 | ... ) |
| 421 | >>> str(url) |
| 422 | 'postgresql+psycopg2://user:pass@host/dbname?alt_host=host1&alt_host=host2&ssl_cipher=%2Fpath%2Fto%2Fcrt' |
| 423 | |
| 424 | :param key_value_pairs: A sequence of tuples containing two strings |
| 425 | each. |
| 426 | |
| 427 | :param append: if True, parameters in the existing query string will |
| 428 | not be removed; new parameters will be in addition to those present. |
| 429 | If left at its default of False, keys present in the given query |
| 430 | parameters will replace those of the existing query string. |
| 431 | |
| 432 | .. versionadded:: 1.4 |
| 433 | |
| 434 | .. seealso:: |
| 435 | |
| 436 | :attr:`_engine.URL.query` |
| 437 | |
| 438 | :meth:`_engine.URL.difference_update_query` |
| 439 | |
| 440 | :meth:`_engine.URL.set` |
| 441 | |
| 442 | """ # noqa: E501 |
| 443 | |
| 444 | existing_query = self.query |
| 445 | new_keys: Dict[str, Union[str, List[str]]] = {} |
| 446 | |
| 447 | for key, value in key_value_pairs: |
| 448 | if key in new_keys: |
| 449 | new_keys[key] = util.to_list(new_keys[key]) |
| 450 | cast("List[str]", new_keys[key]).append(cast(str, value)) |
| 451 | else: |
| 452 | new_keys[key] = ( |
| 453 | list(value) if isinstance(value, (list, tuple)) else value |
| 454 | ) |
| 455 | |
| 456 | new_query: Mapping[str, Union[str, Sequence[str]]] |
| 457 | if append: |
| 458 | new_query = {} |
no test coverage detected