# pgtui

My favorite user interface on a computer is probably the terminal-based text editor. I enjoy typing, syntax highlighting, spellchecking, the navigation, etc. So why not use that as a simple way to insert and update data in a database? That's the goal here, wrapped in a TUI that has additional functionality and which provides the interface to the database overall. All you have to do is provide the connection string via environment variables and voilà! No browser! No forms! No oauth! Just your terminal, your terminal-based editor, and your database.

To insert or update a record in the database, your default terminal editor will open a templated-out [TOML](https://toml.io) file, where each Postgres data type is mapped to a corresponding TOML type.[^1]  Edit as necessary, save and close, and its values are parsed and used in the insert/update query. You can also abandon the insert/update after a file has already been opened by simply uncommenting a line for that purpose. (And, by saving that file elsewhere before abandoning it, you can save it as a draft for submitting later.)

Various usage notes:
  - All available commands can be shown in-app via the `?` key.
  - You can use locally or via a connection tunneled over ssh. Naturally, the tunneled one is a bit slower.
  - If you are entering a multi-line string, toml allows you to surround it with `"""` or `'''`. The first requires escaping special characters, while the latter does not. See [the specification](https://toml.io/en/v1.1.0#string) for more details.

Installation:
  - The recommended way is via Rust's cargo: `cargo install pgtui`.
  - You may also use pre-built binaries, which are available for Linux and Windows at <https://codeberg.org/kdwarn/pgtui/releases>. Download the version for your operating system and remove the OS name from the binary, e.g. rename pgtui-windows.exe to pgtui.exe.
  - A .deb package is also available on the releases page for Debian and derivatives. Install with `apt-get install <path to it>`. (And please let me know about your experience doing so.)

Format for the environment variable in a .env file:
`DATABASE_URL="postgres://user:password@host:port/database"`

**Extra disclaimer, beyond the AGPL license**: This is very much a work in progress and in active development, so don't use it on a database you care about/haven't first backed up.

[^1]: Not all Postgres types are yet handled, and may never be. However the basic ones are - boolean, text, integers, floats, dates, times (without a timezone), timestamps (with or without timezones), arrays (of text), etc. Note that the time for `timestamp with a time zone` will be displayed as local time, however in the future I may make it configurable to display as either local time or UTC. 
