You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
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
@@ -1017,7 +1017,8 @@ Records can be manipulated within transactions for atomic operations:
```python
# Start a transaction
with db.transactions.begin() as transaction:
transaction = db.transactions.begin()
try:
# Create user
user = db.records.create(
"USER",
Expand All
@@ -1044,8 +1045,24 @@ with db.transactions.begin() as transaction:
transaction=transaction
)
# Transaction will automatically commit if no errors occur
# If an error occurs, it will automatically rollback
# Explicitly commit the transaction to make changes permanent
transaction.commit()
except Exception as e:
# Rollback if any error occurs
transaction.rollback()
raise e
# Alternative: Using context manager
with db.transactions.begin() as transaction:
# Perform operations...
user = db.records.create(
"USER",
{"name": "John Doe"},
transaction=transaction
)
# Must explicitly commit - transactions are NOT automatically committed
transaction.commit()
```
---
Expand DownExpand Up
@@ -1280,8 +1297,9 @@ property_with_value = {
Properties API methods support optional transactions for atomic operations:
```python
# Using a transaction
with db.transactions.begin() as transaction:
# Using a transaction with explicit commit
transaction = db.transactions.begin()
try:
# Perform multiple property-related operations
property_to_delete = db.properties.find(
{"where": {"name": "temp_property"}},
Expand All
@@ -1292,7 +1310,29 @@ with db.transactions.begin() as transaction:
property_id=property_to_delete['id'],
transaction=transaction
)
# Transaction will automatically commit if no errors occur
# Explicitly commit the transaction
transaction.commit()
except Exception as e:
# Rollback if any error occurs
transaction.rollback()
raise e
# Alternative: Using context manager (auto-rollback on error)
with db.transactions.begin() as transaction:
# Perform operations
property_to_delete = db.properties.find(
{"where": {"name": "temp_property"}},
transaction=transaction
)[0]
db.properties.delete(
property_id=property_to_delete['id'],
transaction=transaction
)
# Must explicitly commit - transactions are NOT automatically committed
transaction.commit()
```
## Error Handling
Expand All
@@ -1307,3 +1347,246 @@ except RushDBError as e:
print(f"Error: {e}")
print(f"Error Details: {e.details}")
```
---
# LabelsAPI Documentation
The `LabelsAPI` class provides methods for discovering and working with record labels in RushDB. Labels are used to categorize and type records, similar to table names in relational databases.
## Class Definition
```python
class LabelsAPI(BaseAPI):
```
## Methods
### find()
Discovers labels (record types) that exist in the database and can optionally filter them based on search criteria.
**Signature:**
```python
def find(
self,
search_query: Optional[SearchQuery] = None,
transaction: Optional[Transaction] = None
) -> Dict[str, int]
```
**Arguments:**
- `search_query` (Optional[SearchQuery]): Search criteria to filter labels
The `RelationshipsAPI` class provides functionality for querying and analyzing relationships between records in RushDB. Relationships represent connections or associations between different records.
## Class Definition
```python
class RelationshipsAPI(BaseAPI):
```
## Methods
### find()
Search for and retrieve relationships matching the specified criteria with support for pagination and transactions.
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.