Mandala
Tools

Database

Manage workspace databases with CRUD operations

The Database tool provides a powerful way to manage workspace databases directly within your workflows. Create custom database collections, define table schemas, and perform full CRUD (Create, Read, Update, Delete) operations on your data—all without external database services.

With the Database tool, you can:

  • Query data: Retrieve rows from tables with optional filtering and limits
  • Insert data: Add new rows to tables with AI-assisted data generation
  • Update data: Modify existing rows with partial or complete updates
  • Delete data: Soft delete rows or columns from your database
  • Manage schemas: Create tables, add columns, update column properties, and list schema information
  • AI-powered queries: Use the AI wand to automatically generate filters and data structures

The Database tool is ideal for scenarios where you need structured data storage within Mandala—such as maintaining workflow state, storing user preferences, tracking task progress, managing content, or building custom CRM systems. All data stays within your workspace with automatic authentication and access control.

Features

Dynamic Selectors

  • Collection Selector: Browse and select from your workspace's database collections
  • Table Selector: Automatically loads tables based on selected collection
  • Smart Dependencies: Table selector activates only after collection is selected

AI-Powered Data Generation

The Database block includes AI wand integration for three key fields:

  1. Filter Generation: Describe your query in natural language and let AI generate the JSON filter

    • Example: "active users with admin role" → {"status": "active", "role": "admin"}
    • Supports exact matching and array inclusion patterns
    • Tip: Use 'List > Columns' first to see available field names for accurate filtering
  2. Insert Data: Describe the data you want to insert and AI generates the complete row JSON

    • Example: "user John with email john@example.com" → {"name": "John", "email": "john@example.com"}
    • Tip: The AI works best when you provide exact column names. Run 'List > Columns' to see the schema first
  3. Update Data: Describe the changes and AI generates the partial update JSON

    • Example: "set status to active" → {"status": "active"}
    • Tip: If you're unsure of field names, check the schema with 'List > Columns' operation first

Query Filtering

The query operation supports sophisticated filtering:

  • Exact Match: {"status": "active"} - matches rows where status equals "active"
  • Multiple Conditions: {"status": "active", "verified": true} - AND logic
  • Array Inclusion: {"role": ["admin", "moderator"]} - matches if row's role is in the array

Available Operations

Query

Retrieve rows from a table with optional filtering and pagination.

Parameters:

  • Collection (required): Select the database collection
  • Table (required): Select the table to query
  • Filter (optional): JSON object to filter rows (AI wand available)
  • Limit (optional): Maximum number of rows to return (default: 50)

Output:

{
  "rows": [
    {
      "id": "row_123",
      "data": {"name": "John", "email": "john@example.com"},
      "createdAt": "2025-01-15T10:00:00Z",
      "updatedAt": "2025-01-15T10:00:00Z"
    }
  ],
  "count": 1
}

Insert

Add new data to your database.

Row Insert:

  • Collection (required): Select the database collection
  • Table (required): Select the table
  • Data (required): JSON object with field values (AI wand available)

Column Insert:

  • Collection (required): Select the database collection
  • Table (required): Select the table
  • Column Name (required): Name of the new column
  • Column Type (required): Data type (text, number, boolean, date, json)
  • Required (optional): Whether the column is required
  • Default Value (optional): Default value for the column

Output: Created row/column with ID and metadata

Update

Modify existing data in your database.

Row Update:

  • Collection (required): Select the database collection
  • Table (required): Select the table
  • Find Row By (required): Choose how to identify the row
    • By Row ID: Directly specify the row ID (fastest)
    • By Filter: Find row using filter criteria (convenient - no separate query needed!)
  • Row ID (required if "By Row ID"): ID of the row to update
  • Row Filter (required if "By Filter"): JSON filter to find the row (AI wand available)
  • Data (required): JSON object with updated field values (AI wand available)

The "By Filter" option automatically queries for the matching row and updates it in a single operation, eliminating the need for a separate query block.

Column Update:

  • Collection (required): Select the database collection
  • Table (required): Select the table
  • Column ID (required): ID of the column to update
  • New Name (optional): New column name
  • Column Options (optional): JSON object with column settings

Output: Updated row/column with new values

Delete

Remove data from your database (soft delete for rows).

Row Delete:

  • Collection (required): Select the database collection
  • Table (required): Select the table
  • Find Row By (required): Choose how to identify the row
    • By Row ID: Directly specify the row ID (fastest)
    • By Filter: Find row using filter criteria (convenient - no separate query needed!)
  • Row ID (required if "By Row ID"): ID of the row to delete
  • Row Filter (required if "By Filter"): JSON filter to find the row (AI wand available)

The "By Filter" option automatically queries for the matching row and deletes it in a single operation, perfect when you know unique identifiers like email or username.

Column Delete:

  • Collection (required): Select the database collection
  • Table (required): Select the table
  • Column ID (required): ID of the column to delete

Output: Confirmation of deletion

List

Retrieve schema information about your database.

List Tables:

  • Collection (required): Select the database collection

List Columns:

  • Collection (required): Select the database collection
  • Table (required): Select the table

List Rows:

  • Collection (required): Select the database collection
  • Table (required): Select the table
  • Limit (optional): Maximum number of rows to return

Output: Array of tables, columns, or rows with metadata

Common Use Cases

User Management

# Query active admin users
operation: query
collection: users_db
table: users
filter: '{"status": "active", "role": "admin"}'

Content Storage

# Insert a new blog post
operation: insert
insertType: row
collection: content_db
table: posts
data: '{"title": "My Post", "content": "...", "status": "draft"}'

E-commerce

# Find pending and processing orders
operation: query
collection: orders_db
table: orders
filter: '{"status": ["pending", "processing"]}'

CRM System

# Update customer information
operation: update
updateType: row
collection: crm_db
table: customers
rowId: "customer_123"
data: '{"lastContact": "2025-01-15", "notes": "Follow-up completed"}'

Data Types

Supported column types:

  • text: String values
  • number: Integer or decimal values
  • boolean: true/false values
  • date: ISO 8601 timestamp strings
  • json: Complex nested objects and arrays

Auto-Generation Heuristics

(English content replicated for now) Auto-generation retained only for identifier & timestamp patterns.

Identifiers (uuid): id, _id suffix, contains uuid, public_id, external_id, ends key/token. Timestamps (now): lifecycle *_at, camelCase createdAt, updatedAt, suffix timestamp.

System columns always added: id, created_at, updated_at, deleted_at.

PurposeExampleAuto
Identifierorder_iduuid
Public Identifierpublic_iduuid
Session Tokensession_tokenuuid
Creation Timecreated_atnow
Update Timeupdated_atnow
Custom Datedue_date(none)
Domain Fieldstatus(none)

Security

  • Workspace Isolation: Each workspace has its own isolated database collections
  • Authentication: All operations require valid workspace authentication
  • Soft Deletes: Row deletions are soft (set deleted_at timestamp) for data recovery
  • Schema Validation: Column types and constraints are enforced automatically

Best Practices

  1. Discover Schema First: Use 'List > Columns' operation to see table structure before inserting or querying data
  2. Use Filter-Based Updates: When updating/deleting by unique fields (email, username), use "By Filter" option to avoid separate query blocks
  3. Use AI Wands: Let AI generate filters and data structures to avoid JSON syntax errors - but provide schema context
  4. Ensure Unique Filters: When using filter-based update/delete, ensure your filter matches exactly ONE row
  5. Filter Early: Use filters in queries to reduce data transfer and improve performance
  6. Descriptive Names: Use clear collection and table names that reflect their purpose
  7. Schema Planning: Define your column types and constraints before inserting data
  8. Validate Data Types: Ensure inserted data matches the column types defined in your schema
  9. Limit Results: Always set appropriate limits for query operations
  10. Soft Deletes: Remember that deleted rows are only marked as deleted, not removed

Common Use Cases

Discovering Table Schema

Before working with data, check what columns exist:

operation: list
subOperation: columns
collection: "my-collection"
table: "users"

Finding and Updating a Row

Option 1: Using Filter (Recommended - Single Block)

# Update user by email in one operation
operation: update
subOperation: row
rowIdentifierType: filter
collection: "my-collection"
table: "users"
rowFilter: '{"email": "john@example.com"}'
data: '{"status": "active", "verified": true}'

Option 2: Using Row ID (Requires Two Blocks)

# Block 1: Find the row
operation: query
collection: "my-collection"
table: "users"
filter: '{"email": "john@example.com"}'
# Output includes: rows[0].id

# Block 2: Update using the ID
operation: update
subOperation: row
rowIdentifierType: id
collection: "my-collection"
table: "users"
rowId: "{{previous_block.output.rows[0].id}}"
data: '{"status": "active"}'

Deleting a Row by Filter

# Delete inactive user by username in one operation
operation: delete
subOperation: row
rowIdentifierType: filter
collection: "my-collection"
table: "users"
rowFilter: '{"username": "old_account", "status": "inactive"}'

Notes

  • Category: tools
  • Type: database
  • Version: 1.0.0
  • Authentication: Workspace-based (automatic)
Database