|
| 1 | +# tmp-postgres |
| 2 | +--- |
| 3 | + |
| 4 | +`tmp-postgres` is a CLI program to aid in the creation and destruction of |
| 5 | +temporary PostgreSQL instances. |
| 6 | + |
| 7 | +Running |
| 8 | + |
| 9 | +``` |
| 10 | +tmp-postgres <DIRECTORY> |
| 11 | +``` |
| 12 | + |
| 13 | +Initializes a database in `<DIRECTORY>` and starts a postgres server there. By |
| 14 | +default, no tcp ports are listened to. The server is listening on a unix socket |
| 15 | +located in `<DIRECTORY>`. So, you can connect to it with `psql --host |
| 16 | +<DIRECTORY>`. |
| 17 | + |
| 18 | +Alternatively, running |
| 19 | + |
| 20 | +``` |
| 21 | +tmp-postgres <DIRECTORY> --psql |
| 22 | +``` |
| 23 | + |
| 24 | +Does the same thing but launches psql for you in the same terminal. Output from |
| 25 | +child processes (e.g. `initdb`, `postgres`) is line-buffered and forwarded |
| 26 | +along with a tag indicating which child wrote the line. If this is undesirable |
| 27 | +then you can pass `--silent`. |
| 28 | + |
| 29 | +Any arguments after `<DIRECTORY>` are interpreted as a command to run while the |
| 30 | +temporary postgres server runs. So, if you have a test that requires postgres, |
| 31 | +then you could scope a temporary postgres server around it by running |
| 32 | + |
| 33 | +``` |
| 34 | +tmp-postgres <DIRECTORY> <TEST> |
| 35 | +``` |
| 36 | + |
| 37 | +For example: |
| 38 | + |
| 39 | +``` |
| 40 | +# tmp-postgres --silent --remove true /tmp/pg psql --host /tmp/pg -c 'select 1 + 1 as sum' |
| 41 | + sum |
| 42 | +----- |
| 43 | + 2 |
| 44 | +(1 row) |
| 45 | +``` |
| 46 | + |
| 47 | +See `tmp-postgres --help` for additional information. |
| 48 | + |
| 49 | +## Installation |
| 50 | + |
| 51 | +### Cargo |
| 52 | + |
| 53 | +`cd` into `src` and `cargo build` as usual. |
| 54 | + |
| 55 | +### Nix |
| 56 | + |
| 57 | +`nix build` will compile the binary. You can also run it directly with |
| 58 | + |
| 59 | + nix run "github:tstat/tmp-postgres" -- <args> |
| 60 | + |
| 61 | +or add it to your nix registry with |
| 62 | + |
| 63 | + nix registry add tmp-postgres "github:tstat/tmp-postgres" |
| 64 | + |
| 65 | +then you can run it with `nix run tmp-postgres -- <args>` |
0 commit comments