-
-
Notifications
You must be signed in to change notification settings - Fork 18
Add PostgreSQL data store #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6211f03
feat: add PostgreSQL store as async-only implementation
github-actions[bot] 38a059d
refactor: optimize PostgreSQL store to use one-time table setup
github-actions[bot] fcc8f2e
Merge branch 'main' into claude/issue-48-20251027-0100
strawgate 1d9f069
Fix PostgreSQL JSONB serialization and pool initialization issues
github-actions[bot] cd6d584
Fix PostgreSQL JSONB serialization and pool initialization issues
github-actions[bot] d4fc9e1
Refactor PostgreSQL store to use pool directly and remove bulk operat…
github-actions[bot] 380a1fc
Merge branch 'main' into claude/issue-48-20251027-0100
strawgate 61c4d1f
refactor: Simplify JSONB deserialization in PostgreSQL store
github-actions[bot] 99824fb
refactor: simplify PostgreSQL store per code review feedback
github-actions[bot] 9b58ffe
Merge branch 'main' into claude/issue-48-20251027-0100
strawgate 5830173
fix: Fix PostgreSQL test fixture closing pool before tests run
github-actions[bot] 1c615a3
Merge branch 'main' into claude/issue-48-20251027-0100
strawgate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| | Memory | N/A | ✅ | ✅ | Fast in-memory storage for development and caching | | ||
| | Disk | Stable | ☑️ | ✅ | Persistent file-based storage in a single file | | ||
| | Disk (Per-Collection) | Stable | ☑️ | ✅ | Persistent storage with separate files per collection | | ||
| | DuckDB | Unstable | ☑️ | ✅ | In-process SQL OLAP database with native JSON storage | | ||
| | FileTree (test) | Unstable | ☑️ | ✅ | Directory-based storage with JSON files for visual inspection | | ||
| | Null (test) | N/A | ✅ | ✅ | No-op store for testing without side effects | | ||
| | RocksDB | Unstable | ☑️ | ✅ | High-performance embedded database | | ||
|
|
@@ -400,6 +401,7 @@ | |
| | Elasticsearch | Unstable | ✅ | ✅ | Full-text search with key-value capabilities | | ||
| | Memcached | Unstable | ✅ | ✖️ | High-performance distributed memory cache | | ||
| | MongoDB | Unstable | ✅ | ✅ | Document database used as key-value store | | ||
| | PostgreSQL | Unstable | ✅ | ✖️ | PostgreSQL database with JSONB storage | | ||
| | Redis | Stable | ✅ | ✅ | Popular in-memory data structure store | | ||
| | Valkey | Stable | ✅ | ✅ | Open-source Redis fork | | ||
|
|
||
|
|
@@ -569,6 +571,55 @@ | |
|
|
||
| --- | ||
|
|
||
| ### PostgreSQLStore | ||
|
|
||
| PostgreSQL database with JSONB storage for flexible key-value data. | ||
|
|
||
| **Note:** PostgreSQL is async-only. This store uses `asyncpg` which provides native async/await operations. | ||
|
Check failure on line 578 in docs/stores.md
|
||
|
|
||
| ```python | ||
| from key_value.aio.stores.postgresql import PostgreSQLStore | ||
|
|
||
| # Using connection URL | ||
| store = PostgreSQLStore(url="postgresql://localhost:5432/mydb") | ||
|
|
||
| # Using connection parameters | ||
| store = PostgreSQLStore( | ||
| host="localhost", | ||
| port=5432, | ||
| database="mydb", | ||
| user="myuser", | ||
| password="mypass" | ||
| ) | ||
|
|
||
| async with store: | ||
| await store.put(key="user_1", value={"name": "Alice"}, collection="users") | ||
| user = await store.get(key="user_1", collection="users") | ||
| ``` | ||
|
|
||
| **Installation:** | ||
|
|
||
| ```bash | ||
| pip install py-key-value-aio[postgresql] | ||
| ``` | ||
|
|
||
| **Use Cases:** | ||
|
|
||
| - Applications already using PostgreSQL | ||
| - Need for SQL querying on stored data | ||
| - ACID transaction requirements | ||
| - Complex data relationships | ||
|
|
||
| **Characteristics:** | ||
|
|
||
| - JSONB storage for efficient querying | ||
| - TTL support via expiration timestamps | ||
| - Single table design (collections as column values) | ||
| - Async-only (uses asyncpg) | ||
| - Stable storage format: **Unstable** | ||
|
|
||
| --- | ||
|
|
||
| ### MemcachedStore | ||
|
|
||
| High-performance distributed memory caching system. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
key-value/key-value-aio/src/key_value/aio/stores/postgresql/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| """PostgreSQL store for py-key-value-aio.""" | ||
|
|
||
| try: | ||
| from key_value.aio.stores.postgresql.store import PostgreSQLStore | ||
| except ImportError as e: | ||
| msg = 'PostgreSQLStore requires the "postgresql" extra. Install via: pip install "py-key-value-aio[postgresql]"' | ||
| raise ImportError(msg) from e | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| __all__ = ["PostgreSQLStore"] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.