Skip to content

Commit f048432

Browse files
docs: update README and add PostgreSQL to stores documentation
- Remove PostgreSQL from README backends list to match main's simplified format - Add docs/stores.md with PostgreSQL entry in distributed stores section - Apply ruff formatting to PostgreSQL store Co-authored-by: William Easton <strawgate@users.noreply.github.com>
1 parent 60ce922 commit f048432

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ This monorepo contains two libraries:
1717

1818
## Why use this library?
1919

20-
- **Multiple backends**: DynamoDB, Elasticsearch, Memcached, MongoDB, PostgreSQL,
21-
Redis, RocksDB, Valkey, and In-memory, Disk, etc
20+
- **Multiple backends**: DynamoDB, Elasticsearch, Memcached, MongoDB, Redis,
21+
RocksDB, Valkey, and In-memory, Disk, etc
2222
- **TTL support**: Automatic expiration handling across all store types
2323
- **Type-safe**: Full type hints with Protocol-based interfaces
2424
- **Adapters**: Pydantic model support, raise-on-missing behavior, etc

docs/stores.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ Distributed stores provide network-based storage for multi-node applications.
331331
| Elasticsearch | Unstable ||| Full-text search with key-value capabilities |
332332
| Memcached | Unstable || ✖️ | High-performance distributed memory cache |
333333
| MongoDB | Unstable ||| Document database used as key-value store |
334+
| PostgreSQL | Unstable || ✖️ | PostgreSQL-based key-value storage |
334335
| Redis | Stable ||| Popular in-memory data structure store |
335336
| Valkey | Stable ||| Open-source Redis fork |
336337

@@ -500,6 +501,49 @@ pip install py-key-value-aio[mongodb]
500501

501502
---
502503

504+
### PostgreSQLStore
505+
506+
PostgreSQL relational database used as a key-value store.
507+
508+
```python
509+
from key_value.aio.stores.postgresql import PostgreSQLStore
510+
511+
# Using connection URL
512+
store = PostgreSQLStore(url="postgresql://localhost:5432/mydb")
513+
514+
# Using connection parameters
515+
store = PostgreSQLStore(
516+
host="localhost",
517+
port=5432,
518+
database="mydb",
519+
user="myuser",
520+
password="mypass"
521+
)
522+
```
523+
524+
**Installation:**
525+
526+
```bash
527+
pip install py-key-value-aio[postgresql]
528+
```
529+
530+
**Use Cases:**
531+
532+
- Applications already using PostgreSQL
533+
- Need for SQL query capabilities
534+
- ACID compliance requirements
535+
- Relational data with key-value access pattern
536+
537+
**Characteristics:**
538+
539+
- JSONB storage for values
540+
- TTL support via expires_at timestamps
541+
- Optimized bulk operations
542+
- Lazy cleanup of expired entries
543+
- Stable storage format: **Unstable**
544+
545+
---
546+
503547
### MemcachedStore
504548

505549
High-performance distributed memory caching system.

key-value/key-value-aio/src/key_value/aio/stores/postgresql/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ async def _setup_collection(self, *, collection: str) -> None:
270270
index_name = f"idx_{self._table_name}_expires_at"
271271
if len(index_name) > POSTGRES_MAX_IDENTIFIER_LEN:
272272
import hashlib
273+
273274
index_name = "idx_" + hashlib.sha256(self._table_name.encode()).hexdigest()[:16] + "_exp"
274275
create_index_sql = f""" # noqa: S608
275276
CREATE INDEX IF NOT EXISTS {index_name}
@@ -439,8 +440,7 @@ async def _put_managed_entries(
439440

440441
# Prepare data for batch insert using method-level ttl/created_at/expires_at
441442
values = [
442-
(sanitized_collection, key, entry.value, ttl, created_at, expires_at)
443-
for key, entry in zip(keys, managed_entries, strict=True)
443+
(sanitized_collection, key, entry.value, ttl, created_at, expires_at) for key, entry in zip(keys, managed_entries, strict=True)
444444
]
445445

446446
async with self._acquire_connection() as conn:

0 commit comments

Comments
 (0)