-
Notifications
You must be signed in to change notification settings - Fork 1
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
Open
strawgate
wants to merge
2
commits into
main
Choose a base branch
from
claude/issue-48-20251027-0100
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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 | ||
|
|
||
| __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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix line length violation flagged by linter.
The markdown linter expects lines to be ≤80 characters, but this line is 107 characters.
Apply this diff to fix the line length:
📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: Run Tests
[error] 578-578: MD013/line-length Line length [Expected: 80; Actual: 107]. Linting failed as part of 'make lint' (exit code 2).
🪛 GitHub Check: markdown_lint
[failure] 578-578: Line length
docs/stores.md:578:81 MD013/line-length Line length [Expected: 80; Actual: 107] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md013.md
🤖 Prompt for AI Agents