* 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>
`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
* Fix - Raised notices are printed backwards #1443
* updated changelog
* removed a print
* fixed up syntax error
* removing unneeded Nones from output
* rem var due to github recommendation
* adjusting if statements.
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.
When connecting to an IPv4 address (`pgcli -h 127.0.0.1`), trying to
use the "short host" in the prompt (with `\h`) would only display the
first octet (127). Now it shows the full IP.
Fixes#964.
* Fix deprecation.
* Drop python 3.7 and add 3.12.
* Bump pendulum.
* Changelog.
* Update gh actions.
* See if things pass without this scenario.
* Skip failing scenarios in 3.12.
* 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>
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.
* 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
* 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
* 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>
* 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.
* fixing test_config.py to work on windows
* Getting rid of odd characters in wrappager.py
* added a space to a comment to try to kick the github workflow.
Co-authored-by: Eric Young <YoungEricR@JohnDeere.com>
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`
* upgrade prompt-toolit to 3.0
fix: https://github.com/dbcli/pgcli/issues/1148
related:
https://github.com/prompt-toolkit/python-prompt-toolkit/issues/886
in order to make the `behave` test pass, I have to:
- extend timeout for database connection test.
- extend timeout for basic command expect.
- extend timeout for features/steps/crud_table.py:: see data selected.
- disable cpr for features but "run the cli"
* [ci] disable CPR for all behave tests.
* bugfix: remove duplicated prompt expect.
* [ci] delete CPR env setting.
* Revert "[ci] delete CPR env setting."
This reverts commit fe4d5b565e.
* revert the extending timeout back.
* [ci] test when didn't disable CPR.
* Revert "[ci] test when didn't disable CPR."
This reverts commit d379b1e736.
* deprecate Python2.7.
So we can use latest version of prompt-toolit.
Relate: https://github.com/dbcli/pgcli/pull/1149
* black format, remove 2.7 support.
* using version py35 for black.
* Revert "black format, remove 2.7 support."
This reverts commit 4b6d0496cc.
* deprecated py27 using black.
* remove 2.7 from travis.
* update setup.py: delete python 2.7 support.