neumino / thinky

JavaScript ORM for RethinkDB
http://justonepixel.com/thinky/
Other
1.12k stars 128 forks source link

Printing reql statements for debugging #446

Open dtoubelis opened 8 years ago

dtoubelis commented 8 years ago

Is there any parameter I can pass when instantiating thinky that would cause it to print reql statements that are sent to the server? That would be very helpful debugging tool.

neumino commented 8 years ago

You can call toString on a query, as for save, you can't easily print things at the moment.

brandon-beacher commented 8 years ago

I do this in my development environment:

var Thinky = require("thinky");

var thinky = Thinky({
    host: Config.rethink.host,
    port: Config.rethink.port,
    db: Config.rethink.db
});

if (Config.env === "dev") {
    // intercept and output reql in dev environment
    thinky.r._Term.prototype.run = _.wrap(thinky.r._Term.prototype.run, function (func) {
        console.error(this.toString());
        var trailingArguments = [].slice.call(arguments, 1);
        return func.apply(this, trailingArguments);
    });
}
dtoubelis commented 8 years ago

@brandon-beacher That is clever :-) Thanks.