hediet / ts-typed-sql

A fully typed sql builder. Not maintained anymore, use it for your inspiration.
https://hediet.github.io/ts-typed-sql/
54 stars 4 forks source link

debug log sql statements using require('debug') #12

Closed phiresky closed 7 years ago

phiresky commented 7 years ago

I think something like this should be the default

const debugSql = require('debug')('typed-sql');
const qs: QueryService;

qs.onSqlStatement.sub((self, args) => {
    if (debugSql.enabled)
        debugSql(args.sql.substr(0, 400), args.sql.length > 400 ? "..." : "", args.parameters.slice(0, 20), args.parameters.length > 20 ? "..." : "");
});

Then you can debug the SQL statements generated by simly running the process using

DEBUG=typed-sql node script.js

hediet commented 7 years ago

Implemented with this code:

log("Executing SQL query '%s' with args %o", queryText, parameters);

I don't shorten the sql query here as this could be done using a debug formatter.

phiresky commented 7 years ago

What is a "debug formatter"

hediet commented 7 years ago

See https://github.com/visionmedia/debug#formatters