from typing import Union
from pathlib import Path


def create_uri(filename: Union[str, Path], *, mode: str = "ro") -> str:
    """Create SQLite URI (https://www.sqlite.org/uri.html)."""

    filepath = Path(filename)
    uri_path = filepath.as_posix()
    uri_path = uri_path.replace("?", "%3f")
    uri_path = uri_path.replace("#", "%23")
    return f"file:{uri_path}?mode={mode}"