Skip to content

Commit

Permalink
feat(tag): view 컬럼 변경
Browse files Browse the repository at this point in the history
view에서 가져오는 컬럼 변경
  • Loading branch information
nyj001012 committed Jul 18, 2023
1 parent 0878cad commit c860b59
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions backend/src/entity/entities/VTagsSuperDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,42 @@ import { DataSource, ViewColumn, ViewEntity } from 'typeorm';

@ViewEntity('v_tags_super_default', {
expression: `
SELECT sp1.content, (
SELECT COUNT(sp1.id)
SELECT sp1.content,
(SELECT COUNT(sp1.id)
FROM sub_tag sb1
WHERE sb1.superTagId = sp1.id
AND sb1.isDeleted IS FALSE AND sb1.isPublic IS TRUE) AS count
FROM super_tag sp1
WHERE sp1.isDeleted IS FALSE
AND sp1.content != 'default'
AND sb1.isDeleted IS FALSE
AND sb1.isPublic IS TRUE) AS count,
1 AS type,
DATE_FORMAT(sp1.createdAt, '%Y-%m-%d') AS createdAt
FROM super_tag sp1
WHERE sp1.isDeleted IS FALSE
AND sp1.content != 'default'
UNION
SELECT sb2.content,
0 AS count
FROM sub_tag sb2
INNER JOIN super_tag sp2
ON sb2.superTagId = sp2.id
WHERE sp2.content = 'default'
AND sb2.isDeleted IS FALSE
AND sb2.isPublic IS TRUE`,
0 AS count,
0 AS type,
DATE_FORMAT(sb2.createdAt, '%Y-%m-%d') AS createdAt
FROM sub_tag sb2
INNER JOIN super_tag sp2
ON sb2.superTagId = sp2.id
WHERE sp2.content = 'default'
AND sb2.isDeleted IS FALSE
AND sb2.isPublic IS TRUE
`,
})
export class VTagsSuperDefault {
@ViewColumn()
content: string;

@ViewColumn()
count: number;

@ViewColumn()
type: string;

@ViewColumn()
createdAt: string;
}

export default VTagsSuperDefault;

0 comments on commit c860b59

Please sign in to comment.