最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nestjs - How to add no overlaps period constraint using TypeORM decorator? - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Try 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;
}
发布评论

评论列表(0)

  1. 暂无评论