crud icon indicating copy to clipboard operation
crud copied to clipboard

[Feature request] Allow to pass side-data param to typeorm

Open Bnaya opened this issue 5 years ago • 5 comments

Motivation: #68

TypeORM has an ability to pass data as an additional free-shape param to repository operations, that is available on the query runner instance.

// user sends request during entity save
postRepository.save(post, { data: { request: request } });

// in logger you can access it this way:
logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner) {
    const requestUrl = queryRunner && queryRunner.data["request"] ? "(" + queryRunner.data["request"].url + ") " : "";
    console.log(requestUrl + "executing query: " + sql);
}

The example is from the end of: https://github.com/typeorm/typeorm/blob/master/docs/logging.md#using-custom-logger

If the passed data will be configurable somehow (maybe an async callback that gets request context of something more high-level/) it will be possible to implement #68 with

Bnaya avatar Apr 15 '19 10:04 Bnaya

Nothing yet? need to get current user from request on Subscriber....

kevinmelo avatar May 10 '21 15:05 kevinmelo

Same here, @kevinmelo . 🤧

power-f-GOD avatar Aug 27 '22 03:08 power-f-GOD

I found this package (as a work around), and it seems to work for me: https://github.com/Papooch/nestjs-cls

However, this feature would be much appreciated and more reliable.

power-f-GOD avatar Aug 27 '22 05:08 power-f-GOD

Same here, @kevinmelo . 🤧

At the end i using my own framework. And using connection pulls with TypeORM to save the current user from the request at the transaction

kevinmelo avatar Aug 27 '22 11:08 kevinmelo

How did you do that?

power-f-GOD avatar Sep 02 '22 08:09 power-f-GOD