import tempfile
import sqlite3


def _create_lookup_db(rows):
    """Create lookup db file."""
    with tempfile.NamedTemporaryFile(delete=False) as f:
        pass

    conn = sqlite3.connect(f.name)
    with conn:
        conn.execute(
            """
            CREATE TABLE appgroups (
                pattern text,
                group_type text,
                endpoints text,
                data text
            )
            """
        )
        conn.executemany(
            """
            INSERT INTO appgroups (
                pattern, group_type, endpoints, data
            ) VALUES(?, ?, ?, ?)
            """,
            rows
        )
    conn.close()
    return f.name