Size: a a a

TypeORM - Русскоязычное сообщество

2020 January 28

n

neurosys in TypeORM - Русскоязычное сообщество
You make me wonder. In this company, they don't use repository's. Everything is in entity and hooks. I wonder if it's worth arguing for putting everything into repository's.
источник

КБ

Константин Брызгалин in TypeORM - Русскоязычное сообщество
neurosys
> I think it’s wrong to do queries/transactions inside event listener. First there’s a chance to trigger other listeners and eventually cause endless loops.

Even if it's a simple validation? That queries the database, that is
If it’s a syncronous validation, event listeners are okay. If your entity must have a valid relation to another entity, foreign keys are preferred. If this is something complex, you probably should either implement that somewhere else. Options include a) controller method (if it’s a one-time thing) b) repository method (as a part of transaction logic) and c) stored procedure in the database.

I personally avoid stored procedures, they’re hard to keep under version control and debugging is far from simple. Also calling it reqiures use of raw sql and the code is not exactly TypeORM-style (uses createQueryRunner on connection), but if you feel it appropriate for your case – why not…
источник

КБ

Константин Брызгалин in TypeORM - Русскоязычное сообщество
neurosys
You make me wonder. In this company, they don't use repository's. Everything is in entity and hooks. I wonder if it's worth arguing for putting everything into repository's.
I usually start from plain entities and all queries built inside controller methods. At some point, if project grows, certains patterns and repeated queries appear across code base, and copy-pasted code makes it harder to update, and to move forward. That’s where I take a break and refactor to create a repository. Usually it starts from a single repository for a single, most heavily used entity, and if project continues to grow, later repositories get added and more refactoring is done.

Of course, in a small project adding repositories is classic over-engineering…
источник

n

neurosys in TypeORM - Русскоязычное сообщество
Константин Брызгалин
I usually start from plain entities and all queries built inside controller methods. At some point, if project grows, certains patterns and repeated queries appear across code base, and copy-pasted code makes it harder to update, and to move forward. That’s where I take a break and refactor to create a repository. Usually it starts from a single repository for a single, most heavily used entity, and if project continues to grow, later repositories get added and more refactoring is done.

Of course, in a small project adding repositories is classic over-engineering…
Thanks for the detailed suggestions.

Our entities are updated via Controllers (for REST endpoints), but also through a bunch of internal Consumers from various pub-sub channels. So all our "validations" are as Event Listener hooks on the entity. And these validations sometimes query the database.
источник

n

neurosys in TypeORM - Русскоязычное сообщество
So I think it's a safe place to have the validations. Same thoughts for me about the stored procedures.
источник

n

neurosys in TypeORM - Русскоязычное сообщество
So the problem with Transactions and Entity Listeners is that there is no way to access transaction entityManager from inside Entity Listener hooks, so they are outside transaction if they need to query the database.

Pleerock suggests using Entity Subscribers for such cases when you need to query the database within the same transaction. I see that there's a PR related to this here: https://github.com/typeorm/typeorm/pull/4554
источник

n

neurosys in TypeORM - Русскоязычное сообщество
источник

IK

ILshat Khamitov in TypeORM - Русскоязычное сообщество
sir what you want from russian comuniti?
источник
2020 January 29

IK

ILshat Khamitov in TypeORM - Русскоязычное сообщество
оу, привет!
источник

IK

ILshat Khamitov in TypeORM - Русскоязычное сообщество
👋
источник

UK

Umed Khudoiberdiev in TypeORM - Русскоязычное сообщество
источник

BK

Bogdan Korenkov in TypeORM - Русскоязычное сообщество
ого
источник

n

neurosys in TypeORM - Русскоязычное сообщество
ILshat Khamitov
sir what you want from russian comuniti?
It's not my PR. :)
источник

RM

Rustam Mamadaminov in TypeORM - Русскоязычное сообщество
👋
источник

КБ

Константин Брызгалин in TypeORM - Русскоязычное сообщество
open source is tough 🙂
источник

n

neurosys in TypeORM - Русскоязычное сообщество
Same conflicts happen in closed source too, it's just they are not visible to outside world :p. But yeah it could have been solved easier if they worked in the same office.
источник

n

neurosys in TypeORM - Русскоязычное сообщество
      class RequestParam {
       @IsNotEmpty()
       @Expose()
       id!: string;
     }
     class Request {
       @ValidateNested()
       @Expose()
       params!: RequestParam;
     }

     const errors = await validate(plainToClass(Request, request, { excludeExtraneousValues: true }));
     console.log('* errors', errors); // prints []


I wonder what's the issue here.
источник

n

neurosys in TypeORM - Русскоязычное сообщество
neurosys
      class RequestParam {
       @IsNotEmpty()
       @Expose()
       id!: string;
     }
     class Request {
       @ValidateNested()
       @Expose()
       params!: RequestParam;
     }

     const errors = await validate(plainToClass(Request, request, { excludeExtraneousValues: true }));
     console.log('* errors', errors); // prints []


I wonder what's the issue here.
Seems like this is required:
        @Type(() => RequestParam)
источник
2020 January 30

M

Mr.Lorem in TypeORM - Русскоязычное сообщество
Всем привет! Подскажите пожалуйста как сделать фильтр для where который не будет учитывать регистр.
Есть функция которая возвращает фильтр с Like который заимпорчен из typeorm
return {
    name: Like(%${eventSearchName}%),
};
но она учитывает регистр букв, нашёл информация что можно использовать ILIKE но не пойму как переделать функцию под него, что бы возвращать обьект.
источник

IK

ILshat Khamitov in TypeORM - Русскоязычное сообщество
база какая?
источник