Closed betodealmeida closed 7 months ago
Improve the CLI:
emit_statements
repl
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.
shillelagh
Summary
Improve the CLI:
emit_statements
function, which takes lines and emit full SQL statements (handling quotes).repl
function, that handles the REPL prompt and emits SQL lines.These two simplify the CLI loop tremendously:
And made it easy to introduce an TTY check so that we can call
shillelagh
in a pipe, in non-interactive way.Testing instructions