admin管理员组文章数量:1387411
In my nest.js application I have to avoid of Benchmark
table population in case ValidFrom
and ValidUntil
periods are overlapped. As for me the best idea is to use PostgreSQL DB functionality. So I applied the next migration script.
await queryRunner.query(`
ALTER TABLE "Benchmark"
ADD CONSTRAINT no_overlap
EXCLUDE USING GIST (
tsrange("ValidFrom", "ValidUntil", '[]') WITH &&
)
`);
The applied implementation works perfectly and covers many required case, but unfortunately they have not accepted the solution, because in our application migration scripts should be generated by TypeORM.
So my question is
Is it possible to describe mentioned constraint for records avoiding overlapping dates in mentioned earlier columns? How?
In my nest.js application I have to avoid of Benchmark
table population in case ValidFrom
and ValidUntil
periods are overlapped. As for me the best idea is to use PostgreSQL DB functionality. So I applied the next migration script.
await queryRunner.query(`
ALTER TABLE "Benchmark"
ADD CONSTRAINT no_overlap
EXCLUDE USING GIST (
tsrange("ValidFrom", "ValidUntil", '[]') WITH &&
)
`);
The applied implementation works perfectly and covers many required case, but unfortunately they have not accepted the solution, because in our application migration scripts should be generated by TypeORM.
So my question is
Is it possible to describe mentioned constraint for records avoiding overlapping dates in mentioned earlier columns? How?
Share Improve this question asked Mar 17 at 9:11 SerhiiSerhii 7,60516 gold badges69 silver badges126 bronze badges1 Answer
Reset to default 0Try this. I hope this might help. For more: Typeorm Exclusion Feature
@Entity()
@Exclusion(`USING gist ("room" WITH =, tsrange("from", "to") WITH &&)`)
export class RoomBooking {
@Column()
room: string;
@Column()
from: Date;
@Column()
to: Date;
}
本文标签: nestjsHow to add no overlaps period constraint using TypeORM decoratorStack Overflow
版权声明:本文标题:nestjs - How to add no overlaps period constraint using TypeORM decorator? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744570774a2613325.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论