Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Return the last query executed after calling the query() function #288

Open
ryangriggs opened this issue Aug 15, 2024 · 1 comment

Comments

@ryangriggs
Copy link

It would be very helpful for debugging if we could access the complete text of the last query executed upon running the query() function. For example, if there was a lastQuery property of the mariadb object, where the last SQL query string is stored each time the query() function is executed.

Would also be great if this was updated when a prepared statement was executed, so we could actually see the full query text for debugging.

Thanks!

@rusher
Copy link
Collaborator

rusher commented Aug 22, 2024

there is something that might be more appropriate for debugging: the logger option.

Here is a simple example using console :

    const conn = await mariadb.createConnection({
      user: 'myUser', 
      host: 'localhost",
      password: 'myPwd',
      prepareCacheLength: 0,
      logger: {
        network: null,
        query: (msg) => console.log(msg),
        error: (msg) => console.log(msg)
      }
    });
    await conn.query('SELECT ?', [2]);
    await conn.execute('SELECT ?', [2]);

will display:

QUERY: SELECT ? - parameters:[2]
PREPARE: SELECT ?
EXECUTE: (-1) sql: SELECT ? - parameters:[2]
CLOSE PREPARE: (1) SELECT ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants