Skip to content

Commit 116c974

Browse files
committed
add readme
1 parent 05312df commit 116c974

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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>`

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
description = "basic rust project";
2+
description = "Easily start a temporary PostgreSQL server for testing or exploration";
33

44
inputs = {
55
flake-utils.url = "github:numtide/flake-utils";
@@ -30,7 +30,7 @@
3030
"${package-name}" = pkgs.rustPlatform.buildRustPackage {
3131
pname = package-name;
3232
version = "0.1.0";
33-
cargoSha256 = "sha256-o9pxSXyiDS7FFdZmXssY1qQvyya0tTg1nRpMPXd9ZO4=";
33+
cargoSha256 = "sha256-6V1NbCW3y1GA8y8yL5hP/GVNHjdhbsvT31t2iwEfkec=";
3434
src = ./src;
3535
buildInputs =
3636
let

src/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "tmp-postgres"
33
version = "0.1.0"
44
edition = "2021"
55
license = "MIT"
6+
readme = "../README.md"
67
description = """
78
Easily start a temporary PostgreSQL server for testing or exploration
89
"""

0 commit comments

Comments
 (0)