Skip to main content
Version: 1.3.0 (latest)

common.libs.sql_alchemy_shims

Ports fragments of URL class from Sql Alchemy to use them when dependency is not available.

ImmutableDict Objects

class ImmutableDict(Dict[_KT, _VT])

[view_source]

Not a real immutable dict

URL Objects

class URL(NamedTuple)

[view_source]

Represent the components of a URL used to connect to a database.

Based on SqlAlchemy URL class with copyright as below:

engine/url.py

Copyright (C) 2005-2023 the SQLAlchemy authors and contributors

This module is part of SQLAlchemy and is released under

the MIT License: https://www.opensource.org/licenses/mit-license.php

drivername

database backend and driver name, such as postgresql+psycopg2

username

username string

password

password, which is normally a string but may also be any object that has a __str__() method.

host

hostname or IP number. May also be a data source name for some drivers.

port

integer port number

database

database name

query

an immutable mapping representing the query string. contains strings for keys and either strings or tuples of strings for values

create

@classmethod
def create(cls,
drivername: str,
username: Optional[str] = None,
password: Optional[str] = None,
host: Optional[str] = None,
port: Optional[int] = None,
database: Optional[str] = None,
query: Mapping[str, Union[Sequence[str], str]] = None) -> "URL"

[view_source]

Create a new URL object.

set

def set(drivername: Optional[str] = None,
username: Optional[str] = None,
password: Optional[str] = None,
host: Optional[str] = None,
port: Optional[int] = None,
database: Optional[str] = None,
query: Optional[Mapping[str, Union[Sequence[str],
str]]] = None) -> "URL"

[view_source]

return a new URL object with modifications.

update_query_pairs

def update_query_pairs(key_value_pairs: Iterable[Tuple[str, Union[str,
List[str]]]],
append: bool = False) -> "URL"

[view_source]

Return a new URL object with the query parameter dictionary updated by the given sequence of key/value pairs

render_as_string

def render_as_string(hide_password: bool = True) -> str

[view_source]

Render this URL object as a string.

get_backend_name

def get_backend_name() -> str

[view_source]

Return the backend name.

This is the name that corresponds to the database backend in use, and is the portion of the drivername that is to the left of the plus sign.

get_driver_name

def get_driver_name() -> str

[view_source]

Return the backend name.

This is the name that corresponds to the DBAPI driver in use, and is the portion of the drivername that is to the right of the plus sign.

make_url

def make_url(name_or_url: Union[str, URL]) -> URL

[view_source]

Given a string, produce a new URL instance.

The format of the URL generally follows RFC-1738, with some exceptions, including that underscores, and not dashes or periods, are accepted within the "scheme" portion.

If a URL object is passed, it is returned as is.

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.