Skip to content

Commit f37a0b2

Browse files
committed
add --throttle option for batch mode pauses
The --throttle option adds a pause between queries in batch mode, which can be useful for long or intensive scripts. Technically we pause between each line of input, which is usually equivalent to one query.
1 parent 8cb611d commit f37a0b2

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Features
2626
* Make destructive-warning keywords configurable.
2727
* Smarter fuzzy completion matches.
2828
* Stream input from STDIN to consume less memory, adding `--noninteractive` and `--format=` CLI arguments.
29+
* Add `--throttle` option for batch mode.
2930

3031

3132
Bug Fixes

mycli/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from importlib import resources
2020
import itertools
2121
from random import choice
22-
from time import time
22+
from time import sleep, time
2323
from urllib.parse import parse_qs, unquote, urlparse
2424

2525
from cli_helpers.tabular_output import TabularOutputFormatter, preprocessors
@@ -1536,6 +1536,7 @@ def get_last_query(self) -> str | None:
15361536
@click.option(
15371537
'--format', 'batch_format', type=click.Choice(['default', 'csv', 'tsv', 'table']), help='Format for batch or --execute output.'
15381538
)
1539+
@click.option('--throttle', type=float, default=0.0, help='Pause in seconds between queries in batch mode.')
15391540
@click.pass_context
15401541
def cli(
15411542
ctx: click.Context,
@@ -1585,6 +1586,7 @@ def cli(
15851586
password_file: str | None,
15861587
noninteractive: bool,
15871588
batch_format: str | None,
1589+
throttle: float,
15881590
) -> None:
15891591
"""A MySQL terminal client with auto-completion and syntax highlighting.
15901592
@@ -1909,6 +1911,8 @@ def cli(
19091911
try:
19101912
if warn_confirmed:
19111913
mycli.run_query(stdin_text, new_line=True)
1914+
if throttle:
1915+
sleep(throttle)
19121916
except Exception as e:
19131917
click.secho(str(e), err=True, fg="red")
19141918
sys.exit(1)

0 commit comments

Comments
 (0)