Skip to content

Add SQL query comment to aid debugging #30

@seanlinsley

Description

@seanlinsley

It'd be great if the SQL that pco_store generates had a SQL comment like this prefixed to the query:

/* file:a/b.rs */
SELECT * FROM ...

That would make it easier to track down the source of the query from pg_stat_statements, pganalyze, etc.

I haven't tested it but theoretically we can add this with #[track_caller]:

// Mark the function that needs to know its caller's location
#[track_caller]
fn log_call() {
    // Get the location of the caller
    let location = std::panic::Location::caller();
    
    // Extract the file path (returns &str)
    let file_path = location.file(); 
    
    // You can also get the line and column numbers
    let line_number = location.line();
    let column_number = location.column();

    println!("Called from file: {}, line: {}, column: {}", file_path, line_number, column_number);
}

// Example usage from different locations
fn main() {
    log_call();
    another_function();
}

fn another_function() {
    log_call();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions