upsert
Create new database records or update existing ones by merging provided data, ensuring records exist with specified content regardless of current state.
Instructions
Upsert a record: create if it doesn't exist, merge/update if it does.
This tool is perfect when you want to ensure a record exists with specific data, regardless of whether it already exists. It will:
Create a new record with the specified ID if it doesn't exist
Merge the provided data into the existing record if it does exist
Always succeed (unless there's a database error)
Args: thing: The full record ID in format "table:id" (e.g., "user:john", "settings:global") data: The data for the record. If record exists, this will be merged with existing data
Returns: A dictionary containing: - success: Boolean indicating if upsert was successful - data: The record after upserting - created: Boolean indicating if a new record was created (vs updated) - error: Error message if upsert failed (only present on failure)
Examples: >>> await upsert("user:john", {"name": "John Doe", "email": "john@example.com"}) {"success": true, "data": {"id": "user:john", "name": "John Doe", ...}, "created": true}
Input Schema
Name | Required | Description | Default |
---|---|---|---|
data | Yes | ||
thing | Yes |