Skip to main content
ChameleonDB’s Debug mode provides visibility into generated SQL queries, execution times, and row counts — essential for performance optimization and troubleshooting.

Debug Mode Overview

Debug mode outputs:
  • Generated SQL — Exact query sent to PostgreSQL
  • Execution time — Query duration in milliseconds
  • Row count — Number of rows returned
  • Entity name — Which entity was queried
Debug mode only affects query visibility — it does NOT change query execution or results.

Enabling Debug Mode

Add .Debug() to any query chain:
Console output:

Debug Output Examples

Simple Query

Output:

Query with Filters

Output:

Query with Relations (Eager Loading)

Output:

Query with Field Projection

Output:

Debugging Mutations

Debug mode also works with Insert, Update, and Delete operations:

Insert with Debug

Output:

Update with Debug

Output:

Delete with Debug

Output:

Performance Troubleshooting

Identifying Slow Queries

Use Debug mode to find performance bottlenecks:
Output:
If eager loading is slow, consider:
  • Adding database indexes
  • Using field projection (.Select()) to reduce data transfer
  • Paginating large result sets

Checking Generated SQL

Verify that ChameleonDB generates efficient SQL:
Expected efficient SQL:
Good signs:
  • WHERE clauses are combined with AND
  • Only requested fields are selected
  • No unnecessary JOINs

Analyzing N+1 Query Problems

Debug mode helps identify N+1 query issues:

Debugging Common Issues

No Rows Returned

Output:

Filter Not Working

Check the generated SQL to verify filter logic:
Output:

Relation Not Loading

Output:

CLI Debugging Commands

Verify Schema Integrity

Check for vault tampering:
Output:

Check Migration Status

See if migrations are pending:
Output:

View Version History

Debug schema evolution:
Output:

Validate Schema

Check for syntax errors:
Output:

Debug Mode Best Practices

Enable Debug mode for all queries during active development:
Debug output adds overhead — remove before deploying:
Use TRACE output to identify slow queries:
Ensure Include() generates efficient SQL:
Use PostgreSQL’s EXPLAIN for deeper analysis:

Troubleshooting Checklist

Query Returns No Results

1

Enable Debug mode

2

Check generated SQL

Verify the WHERE clause is correct:
3

Run SQL directly in database

4

Check for typos in entity/field names

Slow Query Performance

1

Enable Debug to measure time

2

Identify slow operations

3

Add database indexes

4

Use field projection

Only select needed fields:

Migration Fails

1

Check mode restrictions

If readonly, upgrade:
2

Verify integrity

3

Check DATABASE_URL

4

View detailed error

Next Steps

Query Guide

Learn advanced query patterns

Migration Workflow

Master the migration system

Performance

Optimize query performance

Architecture

Understand system internals