from typing import Union
import pathlib
from typing import Tuple
from typing import Optional
import sqlite3


def export_db_get_last_run(
    export_db: Union[str, pathlib.Path]
) -> Tuple[Optional[str], Optional[str]]:
    """Get last run from export database"""
    conn = sqlite3.connect(str(export_db))
    c = conn.cursor()
    row = c.execute(
        "SELECT datetime, args FROM runs ORDER BY id DESC LIMIT 1;"
    ).fetchone()
    if row:
        return row[0], row[1]
    return None, None