Skip to content

Commit b8f06ca

Browse files
committed
doc: refactor usage, add TOC for README
1 parent 1915d4e commit b8f06ca

File tree

2 files changed

+32
-60
lines changed

2 files changed

+32
-60
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ exec-db: ## Enter the database container
4040
doc-build: ## Build the documentation
4141
cd doc && poetry run sphinx-build -nW . _build
4242

43-
doc-serve: ## Serve the documentation
43+
doc-serve: doc-clean ## Serve the documentation
4444
cd doc && poetry run sphinx-autobuild -nW . _build
4545

4646
doc-clean: ## Clean the documentation

README.md

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010

1111
More flexible [PGMQ Postgres extension](https://github.com/tembo-io/pgmq) Python client that using **sqlalchemy ORM**, supporting both **async** and **sync** `engines`, `sessionmakers` or built from `dsn`.
1212

13+
## Table of Contents
14+
15+
* [pgmq-sqlalchemy](#pgmq-sqlalchemy)
16+
* [Features](#features)
17+
* [Installation](#installation)
18+
* [Getting Started](#getting-started)
19+
* [Postgres Setup](#postgres-setup)
20+
* [Usage](#usage)
21+
* [Issue/ Contributing / Development](#issue-contributing--development)
22+
* [TODO](#todo)
23+
24+
1325
## Features
1426

1527
- Supports **async** and **sync** `engines` and `sessionmakers`, or built from `dsn`.
@@ -32,7 +44,9 @@ pip install pgmq-sqlalchemy[psycopg2]
3244
pip install pgmq-sqlalchemy[asyncpg]
3345
```
3446

35-
## Usage
47+
## Getting Started
48+
49+
### Postgres Setup
3650

3751
Prerequisites: **Postgres** with **PGMQ** extension installed. <br>
3852
For quick setup:
@@ -41,61 +55,11 @@ docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 quay.io
4155
```
4256
> For more information, see [PGMQ](https://github.com/tembo-io/pgmq)
4357
44-
<br>
45-
46-
### Create a client
47-
48-
There are 3 ways to create a client:
49-
- 1. Directly from `dsn`:
50-
```python
51-
from pgmq_sqlalchemy import PGMQueue
52-
53-
client = PGMQueue(dsn='postgresql+psycopg://postgres:postgres@localhost:5432/postgres')
54-
# or async dsn
55-
async_client = PGMQueue(dsn='postgresql+asyncpg://postgres:postgres@localhost:5432/postgres')
56-
```
57-
- 2. From `engine` instance:
58-
```python
59-
from sqlalchemy import create_engine
60-
from pgmq_sqlalchemy import PGMQueue
61-
62-
engine = create_engine('postgresql+psycopg://postgres:postgres@localhost:5432/postgres')
63-
client = PGMQueue(engine=engine)
64-
```
65-
also supports **async** `engine`:
66-
```python
67-
from sqlalchemy.ext.asyncio import create_async_engine
68-
from pgmq_sqlalchemy import PGMQueue
69-
70-
async_engine = create_async_engine('postgresql+asyncpg://postgres:postgres@localhost:5432/postgres')
71-
client = PGMQueue(engine=async_engine)
72-
```
73-
- 3. From `sessionmaker` instance:
74-
```python
75-
from sqlalchemy import create_engine
76-
from sqlalchemy.orm import sessionmaker
77-
from pgmq_sqlalchemy import PGMQueue
78-
79-
engine = create_engine('postgresql+psycopg://postgres:postgres@localhost:5432/postgres')
80-
sessionmaker = sessionmaker(bind=engine)
81-
82-
client = PGMQueue(sessionmaker=sessionmaker)
83-
```
84-
also supports **async** `sessionmaker`:
85-
```python
86-
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
87-
from sqlalchemy.orm import sessionmaker
88-
from pgmq_sqlalchemy import PGMQueue
89-
90-
async_engine = create_async_engine('postgresql+asyncpg://postgres:postgres@localhost:5432/postgres')
91-
async_sessionmaker = sessionmaker(bind=async_engine, class_=AsyncSession)
92-
93-
client = PGMQueue(sessionmaker=async_sessionmaker)
94-
```
95-
96-
### Quick Start
97-
98-
For all methods, see [pgmq-sqlalchemy Document](https://pgmq-sqlalchemy-python.readthedocs.io/en/latest/api/pgmq_sqlalchemy.html).
58+
### Usage
59+
60+
> [!NOTE]
61+
> Check [pgmq-sqlalchemy Document](https://pgmq-sqlalchemy-python.readthedocs.io/en/latest/) for more examples and detailed usage.
62+
9963

10064
`dispatcher.py`:
10165
```python
@@ -109,7 +73,8 @@ pgmq.send('my_queue', {'key': 'value'})
10973

11074
`consumer.py`:
11175
```python
112-
from pgmq_sqlalchemy import PGMQueue, Message
76+
from pgmq_sqlalchemy import PGMQueue
77+
from pgmq_sqlalchemy.schema import Message
11378

11479
pgmq = PGMQueue(dsn='postgresql+psycopg://postgres:postgres@localhost:5432/postgres')
11580
msg:Message = pgmq.read('my_queue')
@@ -121,5 +86,12 @@ if msg:
12186

12287
## Issue/ Contributing / Development
12388

124-
Welcome to open an issue or pull request. <br>
125-
See [`How to Contribute ?` on Online Document]()or [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more information.
89+
Welcome to open an issue or pull request ! <br>
90+
See [`Development` on Online Document](https://pgmq-sqlalchemy-python.readthedocs.io/en/latest/)or [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more information.
91+
92+
## TODO
93+
94+
- [ ] Add **time-based** partition option and validation to `create_partitioned_queue` method.
95+
- [ ] Read(single/batch) Archive Table ( `read_archive` method )
96+
- [ ] Detach Archive Table ( `detach_archive` method )
97+
- [ ] Add `set_vt` utils method.

0 commit comments

Comments
 (0)