Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit be1e509

Browse files
committed
documentation and version 0.1.4
1 parent 2d19bba commit be1e509

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

README.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,62 @@ Postgres testing utility
44

55
## Installation
66

7-
`TODO`
7+
To install `testgres` run:
8+
9+
```
10+
pip install testgres
11+
```
12+
13+
At current state it only works with Python 2.*
814

915
## Usage
1016

11-
```
17+
18+
> Node: by default testgres runs `initdb`, `pg_ctl`, `psql` commands from the `$PATH`. To specify custom postgres installation set environment variable `$PG_CONFIG` and point it to pg_config executable: `export PG_CONFIG=/path/to/pg_config`
19+
20+
Here is an example of how you can use `testgres`
21+
22+
```python
1223
from testgres import get_new_node
1324

1425
try:
15-
node = get_new_node('test')
26+
node = get_new_node('master')
1627
node.init()
1728
node.start()
18-
stdout = node.psql('postgres', 'SELECT 1')
29+
stdout = node.safe_psql('postgres', 'SELECT 1')
1930
print stdout
2031
node.stop()
2132
except ClusterException, e:
2233
node.cleanup()
2334
```
35+
36+
Let's walk through the code. First you create new node:
37+
38+
```python
39+
node = get_new_node('master')
40+
```
41+
42+
`master` here is a node's name, not the database's name. The name matters if you're testing replication. Function get_new_node() only creates directory structure in `/tmp` for cluster. Next line:
43+
44+
```python
45+
node.init()
46+
```
47+
48+
initializes claster. On low level it runs `initdb` command and adds some basic configuration to `postgresql.conf` and `pg_hba.conf` files. Function `init()` accepts optional parameter `allows_streaming` which configures cluster for streaming replication (default is `False`).
49+
Now we are ready to start:
50+
51+
```python
52+
node.start()
53+
```
54+
55+
After this you are able to run queries over the cluster. There is three functions to do that:
56+
57+
* node.psql(database, query) - runs query via `psql` command and returns tuple (error code, stdout, stderr)
58+
* node.safe_psql(database, query) - the same as `psql()` except that it returns only `stdout`. If error occures during the execution then it will throw an exception;
59+
* node.execute(database, query) - connects with postgresql server using `psycopg2` or `pg8000` library (depends on which is installed in your system) and returns two-dimensional array with data.
60+
61+
To stop server run:
62+
63+
```python
64+
node.stop()
65+
```

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
setup(
33
name = 'testgres',
44
packages = ['testgres'],
5-
version = '0.1.3',
5+
version = '0.1.4',
66
description = 'Testing utility for postgresql and it''s extensions',
77
author = 'Ildar Musin',
88
author_email = 'zildermann@gmail.com',

0 commit comments

Comments
 (0)