betodealmeida / shillelagh

Making it easy to query APIs via SQL
MIT License
387 stars 52 forks source link

feat: improve CLI #435

Closed betodealmeida closed 7 months ago

betodealmeida commented 7 months ago

Summary

Improve the CLI:

These two simplify the CLI loop tremendously:

    for query in emit_statements(repl(session)):
        start = time.time()
        results = None
        try:
            cursor.execute(query)
            results = cursor.fetchall()
        except Error as ex:
            print(ex)
            continue

        headers = [t[0] for t in cursor.description or []]
        print(tabulate(results, headers=headers))
        duration = time.time() - start
        print(
            f"({len(results)} row{'s' if len(results) != 1 else ''} "
            f"in {duration:.2f}s)\n",
        )

    connection.close()
    print("GoodBye!")

And made it easy to introduce an TTY check so that we can call shillelagh in a pipe, in non-interactive way.

Testing instructions