Skip to content

Commit 8f86e20

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 7f9842e commit 8f86e20

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
@@ -4,6 +4,7 @@ Upcoming (TBD)
44
Features
55
--------
66
* Add a `--checkpoint=` argument to log successful queries in batch mode.
7+
* Add `--throttle` option for batch mode.
78

89

910
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
@@ -1548,6 +1548,7 @@ def get_last_query(self) -> str | None:
15481548
@click.option(
15491549
'--format', 'batch_format', type=click.Choice(['default', 'csv', 'tsv', 'table']), help='Format for batch or --execute output.'
15501550
)
1551+
@click.option('--throttle', type=float, default=0.0, help='Pause in seconds between queries in batch mode.')
15511552
@click.pass_context
15521553
def cli(
15531554
ctx: click.Context,
@@ -1599,6 +1600,7 @@ def cli(
15991600
password_file: str | None,
16001601
noninteractive: bool,
16011602
batch_format: str | None,
1603+
throttle: float,
16021604
) -> None:
16031605
"""A MySQL terminal client with auto-completion and syntax highlighting.
16041606
@@ -1931,6 +1933,8 @@ def cli(
19311933
sys.exit(1)
19321934
try:
19331935
if warn_confirmed:
1936+
if throttle and counter > 1:
1937+
sleep(throttle)
19341938
mycli.run_query(stdin_text, checkpoint=checkpoint, new_line=True)
19351939
except Exception as e:
19361940
click.secho(str(e), err=True, fg="red")

0 commit comments

Comments
 (0)