Created
May 28, 2020 21:17
-
-
Save AntsiferovMaxim/8db4e4b61d49ebb45dbb1ac1f73ed0d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity('checks') | |
export class ChecksEntity { | |
@PrimaryGeneratedColumn('uuid') | |
id: string; | |
@OneToOne(() => SessionsEntity, session => session.check, {onDelete: 'CASCADE'}) | |
@JoinColumn() | |
session_id: string; | |
@CreateDateColumn() | |
createdAt: Date; | |
@UpdateDateColumn() | |
updatedAt: Date; | |
} | |
@Entity('sessions') | |
export class SessionsEntity { | |
@PrimaryGeneratedColumn('uuid') | |
id: string; | |
@OneToOne( | |
() => ChecksEntity, | |
check => check.session_id, | |
{ nullable: true, onDelete: 'CASCADE' }, | |
) | |
@JoinColumn() | |
check: ChecksEntity; | |
@Column('timestamptz', { nullable: true }) | |
expireAt: Date; | |
@CreateDateColumn() | |
created_at: Date; | |
@UpdateDateColumn() | |
updated_at: Date; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select date, | |
(select count(checks.id) | |
from checks | |
left join sessions s on checks.id = s.check_id | |
where s.workspace_id = '${payload.workspace_id}' | |
and checks.created_at BETWEEN date AND date + INTERVAL '${interval}') count | |
FROM generate_series(CURRENT_DATE - INTERVAL '${last}', CURRENT_DATE, INTERVAL '${interval}') date | |
ORDER BY date; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment