from typing import Union
from pathlib import Path
import sqlite3


def connect_db(location: Union[str, Path]) -> sqlite3.Connection:
    """Connect to the database.
    
    :param location: The path to the database file.
    :return: A :class:sqlite3.Connection object.
    :rtype: sqlite3.Connection
    
    Usage:
    
        >>> loc = 'mkname/data/names.db'
        >>> query = 'select name from names where id = 1;'
        >>> con = connect_db(loc)
        >>> result = con.execute(query)
        >>> tuple(result)
        (('Noah',),)
        >>> disconnect_db(con)
    """
    # Check to make sure the file exists, since sqlite3 fails silently.
    path = Path(location)
    if not path.is_file():
        msg = f'No database at "{path}".'
        raise ValueError(msg)
    
    # Make and return the database connection.
    con = sqlite3.Connection(path)
    return con