-
Notifications
You must be signed in to change notification settings - Fork 0
New Base #2
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
New Base #2
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b5a23e5
Add .vscode folder to .gitignore
lemonyte c35e614
New Base implementation
lemonyte 25e6816
Add preliminary tests
lemonyte 43ec114
Add delete everything example
lemonyte 8fe0e0f
Rename Clients to ApiClients
lemonyte 0b17a84
Update implementation for new API and fix typing issues
lemonyte 802c2d3
Move update payload creation to constructor
lemonyte ac85f5b
Better exception handling and raising
lemonyte bcf0181
Fix a couple typing mistakes
lemonyte e2155d5
Dont do anything when putting no items
lemonyte aaea117
Fix fetch implementation
lemonyte ec20312
Move fetch under update
lemonyte 5d2e20c
Rename fetch to query
lemonyte 74047e4
Add more tests
lemonyte 3fe421d
Add api docs
lemonyte 27192e6
Use query instead of fetch
lemonyte a1b1603
Add python-dotenv for tests
lemonyte 83e9491
Fix update payload
lemonyte c0dccc8
Better type validation
lemonyte 3b2af63
Fix tests
lemonyte fb73cfd
Make validation optional
lemonyte dfb1667
Reduce code duplication
lemonyte b11321c
Make pyright report unnecessary ignores
lemonyte 267dac4
Skip isinstance check on dicts
lemonyte a25c182
Rename FetchResponse to QueryResponse
lemonyte 7892a42
Improve tests and exceptions
lemonyte 90e81af
Add pytest coverage
lemonyte 050ebbe
Update examples
lemonyte df1bd04
pre-commit autoupdate
lemonyte 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 |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| .vscode/ | ||
|
|
||
| # Byte-compiled / optimized / DLL files | ||
| __pycache__/ | ||
| *.py[cod] | ||
|
|
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
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
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,189 @@ | ||
| # Base API | ||
|
|
||
| ## GET /items/{key} | ||
|
|
||
| SDK method: `get(key: str) -> Item` | ||
|
|
||
| Response `200`: | ||
| Returns a single item. | ||
|
|
||
| ```json | ||
| { | ||
| "key": "foo", | ||
| "field1": "bar" | ||
| // ...other item fields | ||
| } | ||
| ``` | ||
|
|
||
| Response `404`: | ||
| Key does not exist. | ||
|
|
||
| ```text | ||
| No content | ||
| ``` | ||
|
|
||
| ## DELETE /items/{key} | ||
|
|
||
| SDK method: `delete(key: str) -> None` | ||
|
|
||
| Response `204`: | ||
| Returns nothing. | ||
|
|
||
| ```text | ||
| No content | ||
| ``` | ||
|
|
||
| ## POST /items | ||
|
|
||
| SDK method: `insert(item: Item) -> Item` | ||
|
|
||
| Request body: | ||
|
|
||
| ```json | ||
| { | ||
| "item": { | ||
| "key": "foo", | ||
| "field1": "bar", | ||
| // ...other item fields | ||
| "__expires": 1727765807 // optional Unix timestamp | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Response `201`: | ||
| Returns a list of items. | ||
|
|
||
| ```json | ||
| [ | ||
| { | ||
| "key": "foo", | ||
| "field1": "bar" | ||
| // ...other item fields | ||
| } | ||
| // ...other items | ||
| ] | ||
| ``` | ||
|
|
||
| Response `409`: | ||
| Key already exists. | ||
|
|
||
| ```text | ||
| No content | ||
| ``` | ||
|
|
||
| ## PUT /items | ||
|
|
||
| SDK method: `put(items: Item[]) -> Item[]` | ||
|
|
||
| Request body: | ||
|
|
||
| ```json | ||
| { | ||
| "items": [ | ||
| { | ||
| "key": "foo", | ||
| "field1": "bar", | ||
| // ...other item fields | ||
| "__expires": 1727765807 // optional Unix timestamp | ||
| } | ||
| // ...other items | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| Response `201`: | ||
| Returns a list of items. | ||
|
|
||
| ```json | ||
| [ | ||
| { | ||
| "key": "foo", | ||
| "field1": "bar" | ||
| // ...other item fields | ||
| } | ||
| // ...other items | ||
| ] | ||
| ``` | ||
|
|
||
| ## PATCH /items/{key} | ||
|
|
||
| SDK method: `update(updates: Mapping, key: str) -> Item` | ||
|
|
||
| Request body: | ||
|
|
||
| ```json | ||
| { | ||
| "set": { | ||
| "field1": "bar", | ||
| // ...other item fields | ||
| "__expires": 1727765807 // optional Unix timestamp | ||
| }, | ||
| "increment": { | ||
| "field2": 1, | ||
| "field3": -2 | ||
| }, | ||
| "append": { | ||
| "field4": ["baz"] | ||
| }, | ||
| "prepend": { | ||
| "field5": ["foo", "bar"] | ||
| }, | ||
| "delete": ["field6"] | ||
| } | ||
| ``` | ||
|
|
||
| Response `200`: | ||
| Returns a single item. | ||
|
|
||
| ```json | ||
| { | ||
| "key": "foo", | ||
| "field1": "bar" | ||
| // ...other item fields | ||
| } | ||
| ``` | ||
|
|
||
| Response `404`: | ||
| Key does not exist. | ||
|
|
||
| ```text | ||
| No content | ||
| ``` | ||
|
|
||
| ## GET /query | ||
|
|
||
| SDK method: `fetch(*query: Query) -> Item[]` | ||
|
|
||
| Request body: | ||
|
|
||
| ```json | ||
| { | ||
| "limit": 10, | ||
| "last_key": "foo", | ||
| "query": [ | ||
| { | ||
| "field1": "foo", | ||
| "field4?contains": "bar" | ||
| // multiple conditions are ANDed | ||
| }, | ||
| { | ||
| "field3?gt": 2 | ||
| } | ||
| // multiple queries are ORed | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| Response `200`: | ||
| Returns a list of items. | ||
|
|
||
| ```json | ||
| [ | ||
| { | ||
| "key": "foo", | ||
| "field1": "bar" | ||
| // ...other item fields | ||
| } | ||
| // ...other items | ||
| ] | ||
| ``` |
Empty file.
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 |
|---|---|---|
| @@ -1,44 +1,40 @@ | ||
| from contiguity_base import connect | ||
|
|
||
| # Initialize the Contiguity client | ||
| db = connect("api-key", "project-id") | ||
|
|
||
| # Create a Base instance | ||
| my_base = db.Base("randomBase9000") | ||
|
|
||
| # Helper function to print results | ||
| def print_result(operation, result): | ||
| print(f"{operation} result: {result}") | ||
| if result is None: | ||
| print(f"Warning: {operation} operation failed!") | ||
|
|
||
| # Put an item with a specific key | ||
| result1 = my_base.put({"value": "Hello world!"}, "my-key-py") | ||
| print_result("Put", result1) | ||
|
|
||
| # Insert an item with a specific key | ||
| result2 = my_base.insert({"name": "John Doe", "age": 30}, "john-doe-py") | ||
| print_result("Insert", result2) | ||
|
|
||
| # Insert an item with a specific key and expireIn | ||
| result3 = my_base.insert({"name": "Jane Doe", "age": 28}, "jane-doe-py", expire_in=3600) | ||
| print_result("Insert with expireIn", result3) | ||
|
|
||
| # Get an item | ||
| get_result = my_base.get("john-doe-py") | ||
| print_result("Get", get_result) | ||
|
|
||
| # Update an item | ||
| update_result = my_base.update({"age": 31}, "john-doe-py") | ||
| print_result("Update", update_result) | ||
|
|
||
| # Fetch items | ||
| try: | ||
| fetch_result = my_base.fetch({"age": {"$gt": 25}}, limit=10) | ||
| print_result("Fetch", fetch_result) | ||
| except Exception as e: | ||
| print(f"Fetch operation failed: {str(e)}") | ||
|
|
||
| # Delete an item | ||
| delete_result = my_base.delete("jane-doe-py") | ||
| print_result("Delete", delete_result) | ||
| # ruff: noqa: T201 | ||
| from contiguity_base import Base | ||
|
|
||
| # Create a Base instance. | ||
| db = Base("my-base") | ||
|
|
||
| # Put an item with a specific key. | ||
| put_result = db.put({"key": "foo", "value": "Hello world!"}) | ||
| print("Put result:", put_result) | ||
|
|
||
| # Put multiple items. | ||
| put_result = db.put({"key": "bar", "value": "Bar"}, {"key": "baz", "value": "Baz"}) | ||
| print("Put many result:", put_result) | ||
|
|
||
| # Insert an item with a specific key. | ||
| insert_result = db.insert({"key": "john-doe", "name": "John Doe", "age": 30}) | ||
| print("Insert result:", insert_result) | ||
|
|
||
| # Insert an item with a specific key that expires in 1 hour. | ||
| expiring_insert_result = db.insert({"key": "jane-doe", "name": "Jane Doe", "age": 28}, expire_in=3600) | ||
| print("Insert with expiry result:", expiring_insert_result) | ||
|
|
||
| # Get an item using a key. | ||
| get_result = db.get("foo") | ||
| print("Get result:", get_result) | ||
|
|
||
| # Update an item. | ||
| update_result = db.update({"age": db.util.increment(2), "name": "Mr. Doe"}, key="john-doe") | ||
| print("Update result:", update_result) | ||
|
|
||
| # Query items. | ||
| query_result = db.query({"age?gt": 25}, limit=10) | ||
| print("Query result:", query_result) | ||
|
|
||
| # Delete an item. | ||
| db.delete("jane-doe-py") | ||
|
|
||
| # Delete all items. | ||
| for item in db.query().items: | ||
| db.delete(str(item["key"])) |
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.
imo we should go back to how the old SDK was initialised.