Normalize a database specifier into a connection URL. Accepts a plain path to a ``.db`` file (relative or absolute) and converts it to a ``sqlite:///`` URL. Anything that already looks like a DB URL (``sqlite:///``, ``postgresql://``, ...) is passed through unchanged.
(url: str)
| 6 | |
| 7 | |
| 8 | def _resolve_db_url(url: str) -> str: |
| 9 | """Normalize a database specifier into a connection URL. |
| 10 | |
| 11 | Accepts a plain path to a ``.db`` file (relative or absolute) and converts |
| 12 | it to a ``sqlite:///`` URL. Anything that already looks like a DB URL |
| 13 | (``sqlite:///``, ``postgresql://``, ...) is passed through unchanged. |
| 14 | """ |
| 15 | if "://" in url: |
| 16 | return url |
| 17 | return "sqlite:///" + os.path.abspath(os.path.expanduser(url)) |
| 18 | |
| 19 | |
| 20 | def _resolve_from_config(config_path: str) -> tuple[str, str, str]: |
no outgoing calls