1
0
Fork 0
Commit Graph

482 Commits

Author SHA1 Message Date
saucoide ce7f76a676
Add --log-file & \log-file option to always capture output (#1461)
* Add --log-file & \log-file option to always capture output

Currently outputting to a file via \o disables the console output
This patch adds a `--log-file` cli arg with similar behavior to `psql`* and a \log-file
special command to enable/disable it from the console

*https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-OPTION-LOG-FILE

* switch to use context manager

Co-authored-by: Irina Truong <637013+j-bennet@users.noreply.github.com>

* switch to use context manager

Co-authored-by: Irina Truong <637013+j-bennet@users.noreply.github.com>

* use isoformat explicitly

Co-authored-by: Irina Truong <637013+j-bennet@users.noreply.github.com>

* change test to use a mock, update changelog & authors

* reformat

* black

---------

Co-authored-by: Irina Truong <637013+j-bennet@users.noreply.github.com>
2024-04-30 19:03:31 -07:00
Andrew 8cc22b9d3a
Add verbose_errors config and special command (#1455)
* Add verbose_errors config

* Update changelog

* Add special command

* Blackify
2024-03-26 15:31:38 -07:00
Andrew a7a70fdc92
Echo notifications (#1385)
* Echo notifications

* Blackify

* Clean up a bit

* Add test

* Blackify

* Update changelog

* Fix tests
2024-03-23 13:24:40 -07:00
Damien Baty 9f114c4549 feat: Replace pendulum by home-made duration-to-words function
`pgcli` uses Pendulum to display the query execution time in words:

    > select pg_sleep(62)
    +----------+
    | pg_sleep |
    |----------|
    |          |
    +----------+
    SELECT 1
    Time: 62.066s (1 minute 2 seconds), executed in: 62.063s (1 minute 2 seconds)

Pendulum 3 (which has been released in December 2023 and is now
written in Rust) does not build on 32-bit architectures [1]. As such,
installing `pgcli` on such architectures fails. We could pin Pendulum
to version 2 (which was written in Python and builds "everywhere"),
but requiring a whole library and its own dependencies for such a
small feature seems unwarranted.

This commit thus removes the requirement on Pendulum and replaces it
by a simple "duration-to-words" function.

Fixes #1451.

[1] Upstream issue: https://github.com/sdispater/pendulum/issues/784
2024-02-20 12:51:20 +01:00
Antonio e2ff38d170
Support PGAPPNAME (#1444)
The application_name to be used when connecting to a database can now be
specified as a command line argument (--application-name) or be taken
directly from environment variables (PGAPPNAME). It still defaults to
'pgcli' when not specified.

Closes #1421.
2023-12-08 20:21:28 -08:00
Rob Berry 97a1fd6c16
Allow defining a json file with preferred aliases (#1382)
* fix psycopg.sql.Identifier in \ev handling (#1384)

* Allow defining a json file with preferred aliases

At $WORK we have a lot of tables with names like `foo_noun_verb` or
`foo_noun_related-noun_verb` and so while the default aliasing is very
helpful for shortening unwieldy names we do end up with lots of aliases
like `LEFT JOIN fnv on fnv2.id = fnv.fnv2_id`

This change will allow defining a json file of preferred aliases

```
> cat ~/.config/pgcli/aliases.json
{
    "foo_user": "user",
    "foo_user_group": "user_group"
}
```

so the alias suggestion for `SELECT * FROM foo_user` will be `SELECT * FROM foo_user AS user`
instead of the default `SELECT * FROM foo_user AS fu`

* When cannot open or parse alias_map_file raise error

Raise a (hopefully) helpful exception when the alias_map_file cannot be
parsed or does not exist

* Add tests for load_alias_map_file

* Add tests for generate_alias

* Update AUTHORS file

* Remove comment.

Discussed this on the PR with a project maintainer

---------

Co-authored-by: Andy Schoenberger <akschoenberger@gmail.com>
Co-authored-by: Rob B <rob@example.com>
Co-authored-by: Irina Truong <i.chernyavska@gmail.com>
2023-10-06 16:13:28 -07:00
ERYoung11 43360b5d1b
Added \echo & \qecho for Issue #1335 (#1371)
* Added \echo & \qecho for Issue #1335

* black + changelog updates

* trying to re-kick build process
2023-10-06 15:56:48 -07:00
Damien Baty cdfa35830b
Ask for confirmation to quit cli if a transaction is ongoing. (#1400)
If user tries to quit the cli while a transaction is ongoing (i.e.
begun, but not committed or rolled back yet), pgcli now asks for a
confirmation. The user can choose to commit, rollback or cancel the
exit. If the user chooses to commit or rollback, we exit only if the
commit/rollback succeeds.

Fixes #1071.
2023-09-26 21:36:59 -07:00
Damien Baty d8eb8b5b82 Apply black (version 23.1.0) 2023-03-18 14:00:38 +01:00
Damien Baty 1c071770bb Remove leftovers of Python 2 support 2023-03-18 10:22:12 +01:00
Damien Baty a93442aed7 lint: Remove unused variables and imported functions 2023-03-08 09:42:43 +01:00
Damien Baty f4dc796941 Add config option to require a transaction for destructive statements
When this option is on, any statement that is deemed destructive
(through the use of the `destructive_warning` config option) will
not be executed unless a transaction has been started.
2023-03-08 09:42:43 +01:00
Andy Schoenberger 8ef5392fd1
fix explain output when running with auto-vertical-output or max_width (#1396) 2023-02-27 15:20:59 -08:00
Andy Schoenberger 141873f86d
Add config option to always run with a single connection (#1386)
Co-authored-by: Irina Truong <i.chernyavska@gmail.com>
2023-01-03 13:52:31 -08:00
Andy Schoenberger d6ca4c3464
Add config option to not automatically restart connection on destructive warning abort; defaults to not restarting. (#1379) 2022-11-17 20:13:05 -08:00
Andy Schoenberger 431c256567
Add config option to not automatically retry connections with operational errors (#1380) 2022-11-11 09:36:41 -08:00
Rodrigo Neri (Rigo) 1726ff5397
Changed destructive_warning to take a list of destructive commands (#1328)
* Changed destructive_warning to take a list of destructive commands and added the dsn_alias as part of the destructive command warning

* Updated parse_destructive_warning to handle None

* Reverted auto formatted change to AUTHORS

* Reverted auto formatted change to AUTHORS
2022-10-13 14:42:22 -07:00
astroshot c0e1081405
Feature: Add new formatter to export data to sql like mycli (#1366)
* Sub: Add new formatter to export data to sql like mycli

Body: New formatter is added, we can export query result to sql
insertion like mycli

==== End ====

* Sub: Install black and reformat code

Body:

==== End ====

* Sub: Add unit tests for new formatter

Body:

==== End ====

* Sub: Add new formatter to pgclirc
2022-09-14 17:41:40 -07:00
Amjith Ramanujam abc03c509f
Merge pull request #1341 from dbcli/fix-csv-status
Show status in csv format.
2022-09-02 13:57:11 -07:00
Irina Truong 165818bee3 More generic try/catch when dealing with keyring. 2022-06-10 10:27:54 -07:00
Irina Truong 18071754bc
Port to psycopg3 (#1324)
* WIP.

* Add some comments about porting from psycopg 2 to 3 (#1318)

* WIP

* Disable _set_wait_callback()

* TransactionStatus.

* First working query.

* More pg3 changes.

* test_pgexecute still fails.

* Fix bytea support.

* Fix json and enum unicode.

* Get unit tests to pass.

* Behave tests still break, WIP.

* Prompt seems to be displayed fine, why don't the tests see the whitespace?

* Python version.

* Fix test.

* Black.

* Added black to dev reqs.

* nbu link for donations.

* Use psycopg.sql to format statement.

* Special case for show help in pgbouncer.

* Fix test.

* Added integration test.

* Install pgbouncer in ci.

* Fix integration test.

* Remove tmate session.

* Revert commenting out python versions.

* Pin pgspecial to >=2.

* Changelog.

Co-authored-by: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Co-authored-by: Amjith Ramanujam <amjith.r@gmail.com>
2022-06-06 11:20:48 -07:00
Amjith Ramanujam 4485dcc9b0
Merge branch 'main' into fix-csv-status 2022-05-22 20:44:35 -07:00
Amjith Ramanujam a0980e7241 Show status in csv format. 2022-05-22 20:41:27 -07:00
Daniel Kukula 372da81ec4
add explain visualizer (#1279)
* add explain visualizer

* format files

* remove humanize dependency

* disable by default

* add explain visualizer

* run black
2022-04-03 19:20:02 -07:00
Irina Truong 00bed0bdad Black. 2022-03-01 20:15:05 -08:00
Irina Truong 2eef64c8ce Add rowcount to status returned from redshift. 2022-03-01 20:02:31 -08:00
Daniele Varrazzo 25eb9f541b
Add some comments about porting from psycopg 2 to 3 (#1318) 2022-02-22 09:02:16 -08:00
Bruno Inec 54f0cc9ddd
ssh tunnels: allow configuring auto matches (#1302) 2022-02-21 10:20:11 -08:00
Bruno Inec ed9d123073
Add SSH tunnel support (#1301)
* Add initial sshtunnel support

* Force CI to rerun.

* Fix unit test for 3.6.

* Black.

Co-authored-by: Irina Truong <i.chernyavska@gmail.com>
2022-02-18 14:57:42 -08:00
Amjith Ramanujam 338ea2186e Change the order for password prompt and keychain. 2022-01-13 09:27:47 -08:00
Saif Hakim 123e00a086
Re-run last query with bare `\watch` (#1283)
* Re-run last query with bare `\watch`

* add test

* clean up post test refactor

* lint

* rerun tests
2021-09-30 12:00:31 -07:00
Irina Truong c65495716d
Add setting in config to control truncating field values. (#1285)
* Add setting in config to truncate field value.

* Black.

* Changelog.

* Fix tests.
2021-09-03 16:58:03 -07:00
Irina Truong e0a4c18c4a
Another attempt to fix pgbouncer error (1093.) (#1097)
* Another attempt to fix pgbouncer error (1093.)

* Fixes for various pgbouncer problems.

* different approach with custom cursor.

* Fix rebase.

* Missed this.

* Fix completion refresher test.

* Black.

* Unused import.

* Changelog.

* Fix race condition in test.

* Switch from is_pgbouncer to more generic is_virtual_database, and duck-type it. Add very dumb unit test for virtual cursor.

* Remove debugger code.
2021-05-21 15:32:34 -07:00
Amjith Ramanujam 6309dd4f93 Blacken. 2021-05-06 21:20:12 -07:00
Amjith Ramanujam 2fe94c38b4 Black formatting. 2021-05-05 21:01:12 -07:00
Paweł Sacawa 8de796c59c Fix: ANSI escape codes in first line make the cli choose expanded output incorrectly...
The format_output chooses to output as a table or in the expanded
format on the basis of the length of the first line of the table
formatter (`len`). However, this first line contains a lot of ANSI
excape codes, so this comparison is wrong, and the expanded mode
is used either way. This patch strips these escape codes before the
comparison.
2021-05-02 18:18:35 -04:00
Irina Truong 954b8c3902
Use configured pager if table format is csv. (#1260)
* Use configured pager if table format is csv.

* Changelog.

* Simplify.
2021-03-12 14:14:09 -08:00
ERYoung11 bca1d94f39 skipping initial comments in pgconfig file did not work on Windows. 2021-03-10 13:15:58 -06:00
Irina Truong 291878bb31 Black. 2021-02-26 12:44:04 -08:00
Irina Truong d67272214c Preserve comments when writing to config file. 2021-02-26 12:41:04 -08:00
Georgy Frolov c9fd72449e
skip initial comment in pg_session file (#1245)
* skip initial comment in pg_session file

* add test
2021-02-22 14:55:55 -08:00
Irina Truong 0679757d43
Remove gitter links, update build status badge. (#1244) 2021-02-17 16:54:29 -08:00
Irina Truong a3287c4ab2
Finer control over destructive warning. (#1242)
* Finer control over destructive warning.

* Review feedback.

* Changelog.

* Run integration tests with --warn=moderate.

* Fix typo.

* Black.
2021-02-12 21:09:38 -08:00
Miroslav Šedivý 762fb4b8da
Modernize code to Python 3.6+ (#1229)
1. `class A(object)` can be written as `class A:`
2. replace `dict([…])` and `set([…])` with `{…}`
3. use f-strings or compact `.format`
4. use `yield from` instead of `yield` in a `for` loop
5. import `mock` from `unittest`
6. expect `OSError` instead of `IOError` or `select` error
7. use Python3 defaults for file reading or `super()`
8. remove redundant parenthesis (keep those in tuples though)
9. shorten set intersection instead of creating lists
10. backslashes in strings do not have to be escaped if prepended with `r`
2021-02-12 21:34:56 +02:00
laixintao 13bd678ccd
format code using black. 2020-09-14 10:27:46 +08:00
Tom Caruso 223015a1fa
More explicit error message when DSN alias is not found (#1198)
* add a specific error message when DSN with provided alias is not found

* update changelog & authors file
2020-07-31 10:25:06 -07:00
Tom Caruso 8f7e314508
Move from humanize to pendulum library for displaying query durations (#1199) 2020-07-28 23:08:19 -07:00
Irina Truong 901ef31fd1
Fix bug introduced in #1102. (#1178) 2020-05-07 16:41:23 -07:00
pmav99 bcb0c8bce7
Add support for using pspg as the pager. (#1173)
* Stop printing "status" when table_format is "csv"

* Use the "unix" dialect on *nix for CSV output.

* Use a pager when `pspg` has been configured with CSV "table_format".

Fix #1102
2020-04-23 10:17:40 -07:00
Amjith Ramanujam 64c0b3553d
Merge pull request #1171 from dbcli/bugfix/no-new-line
bugfix: don't echo a newline when output is empty.
2020-04-18 19:06:25 -07:00