|
|
@ -43,8 +43,26 @@ func (q *Queries) ClearTagsByTarget(ctx context.Context, arg ClearTagsByTargetPa |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
const clearTagsByTargetLike = `-- name: ClearTagsByTargetLike :exec |
|
|
|
DELETE FROM common_tag |
|
|
|
WHERE target_kind=$1::TEXT |
|
|
|
AND target_id=$2::TEXT |
|
|
|
AND tag LIKE $3::TEXT |
|
|
|
` |
|
|
|
|
|
|
|
type ClearTagsByTargetLikeParams struct { |
|
|
|
TargetKind string `json:"target_kind"` |
|
|
|
TargetID string `json:"target_id"` |
|
|
|
TagLike string `json:"tag_like"` |
|
|
|
} |
|
|
|
|
|
|
|
func (q *Queries) ClearTagsByTargetLike(ctx context.Context, arg ClearTagsByTargetLikeParams) error { |
|
|
|
_, err := q.db.ExecContext(ctx, clearTagsByTargetLike, arg.TargetKind, arg.TargetID, arg.TagLike) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
const selectDistinctTags = `-- name: SelectDistinctTags :many |
|
|
|
SELECT DISTINCT tag FROM common_tag |
|
|
|
SELECT DISTINCT tag FROM common_tag ORDER BY tag |
|
|
|
` |
|
|
|
|
|
|
|
func (q *Queries) SelectDistinctTags(ctx context.Context) ([]string, error) { |
|
|
@ -70,12 +88,12 @@ func (q *Queries) SelectDistinctTags(ctx context.Context) ([]string, error) { |
|
|
|
return items, nil |
|
|
|
} |
|
|
|
|
|
|
|
const selectDistinctTagsByKind = `-- name: SelectDistinctTagsByKind :many |
|
|
|
SELECT DISTINCT tag FROM common_tag WHERE tag LIKE '$1::text%' |
|
|
|
const selectDistinctTagsLike = `-- name: SelectDistinctTagsLike :many |
|
|
|
SELECT DISTINCT tag FROM common_tag WHERE tag LIKE $1::text ORDER BY tag |
|
|
|
` |
|
|
|
|
|
|
|
func (q *Queries) SelectDistinctTagsByKind(ctx context.Context) ([]string, error) { |
|
|
|
rows, err := q.db.QueryContext(ctx, selectDistinctTagsByKind) |
|
|
|
func (q *Queries) SelectDistinctTagsLike(ctx context.Context, dollar_1 string) ([]string, error) { |
|
|
|
rows, err := q.db.QueryContext(ctx, selectDistinctTagsLike, dollar_1) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
@ -98,7 +116,7 @@ func (q *Queries) SelectDistinctTagsByKind(ctx context.Context) ([]string, error |
|
|
|
} |
|
|
|
|
|
|
|
const selectTagsByTag = `-- name: SelectTagsByTag :many |
|
|
|
SELECT tag, target_kind, target_id FROM common_tag WHERE tag = $1::text |
|
|
|
SELECT tag, target_kind, target_id FROM common_tag WHERE tag = $1::text ORDER BY tag |
|
|
|
` |
|
|
|
|
|
|
|
func (q *Queries) SelectTagsByTag(ctx context.Context, tagName string) ([]CommonTag, error) { |
|
|
@ -125,7 +143,7 @@ func (q *Queries) SelectTagsByTag(ctx context.Context, tagName string) ([]Common |
|
|
|
} |
|
|
|
|
|
|
|
const selectTagsByTags = `-- name: SelectTagsByTags :many |
|
|
|
SELECT tag, target_kind, target_id FROM common_tag WHERE tag = ANY($1::text[]) |
|
|
|
SELECT tag, target_kind, target_id FROM common_tag WHERE tag = ANY($1::text[]) ORDER BY tag |
|
|
|
` |
|
|
|
|
|
|
|
func (q *Queries) SelectTagsByTags(ctx context.Context, tagNames []string) ([]CommonTag, error) { |
|
|
@ -152,16 +170,16 @@ func (q *Queries) SelectTagsByTags(ctx context.Context, tagNames []string) ([]Co |
|
|
|
} |
|
|
|
|
|
|
|
const selectTagsByTarget = `-- name: SelectTagsByTarget :many |
|
|
|
SELECT tag, target_kind, target_id FROM common_tag WHERE target_kind = $1 AND target_id = $2::text |
|
|
|
SELECT tag, target_kind, target_id FROM common_tag WHERE target_kind = $1 AND target_id = $2::text ORDER BY tag |
|
|
|
` |
|
|
|
|
|
|
|
type SelectTagsByTargetParams struct { |
|
|
|
TargetKind string `json:"target_kind"` |
|
|
|
Column2 string `json:"column_2"` |
|
|
|
TargetID string `json:"target_id"` |
|
|
|
} |
|
|
|
|
|
|
|
func (q *Queries) SelectTagsByTarget(ctx context.Context, arg SelectTagsByTargetParams) ([]CommonTag, error) { |
|
|
|
rows, err := q.db.QueryContext(ctx, selectTagsByTarget, arg.TargetKind, arg.Column2) |
|
|
|
rows, err := q.db.QueryContext(ctx, selectTagsByTarget, arg.TargetKind, arg.TargetID) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
@ -184,16 +202,16 @@ func (q *Queries) SelectTagsByTarget(ctx context.Context, arg SelectTagsByTarget |
|
|
|
} |
|
|
|
|
|
|
|
const selectTagsByTargets = `-- name: SelectTagsByTargets :many |
|
|
|
SELECT tag, target_kind, target_id FROM common_tag WHERE target_kind = $1 AND target_id = ANY($2::text[]) |
|
|
|
SELECT tag, target_kind, target_id FROM common_tag WHERE target_kind = $1 AND target_id = ANY($2::text[]) ORDER BY tag |
|
|
|
` |
|
|
|
|
|
|
|
type SelectTagsByTargetsParams struct { |
|
|
|
TargetKind string `json:"target_kind"` |
|
|
|
Column2 []string `json:"column_2"` |
|
|
|
TargetIds []string `json:"target_ids"` |
|
|
|
} |
|
|
|
|
|
|
|
func (q *Queries) SelectTagsByTargets(ctx context.Context, arg SelectTagsByTargetsParams) ([]CommonTag, error) { |
|
|
|
rows, err := q.db.QueryContext(ctx, selectTagsByTargets, arg.TargetKind, pq.Array(arg.Column2)) |
|
|
|
rows, err := q.db.QueryContext(ctx, selectTagsByTargets, arg.TargetKind, pq.Array(arg.TargetIds)) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
@ -215,6 +233,38 @@ func (q *Queries) SelectTagsByTargets(ctx context.Context, arg SelectTagsByTarge |
|
|
|
return items, nil |
|
|
|
} |
|
|
|
|
|
|
|
const selectTargetsByTags = `-- name: SelectTargetsByTags :many |
|
|
|
SELECT DISTINCT(target_id) FROM common_tag WHERE tag = ANY($1::text[]) AND target_kind = $2::text ORDER BY tag |
|
|
|
` |
|
|
|
|
|
|
|
type SelectTargetsByTagsParams struct { |
|
|
|
TagNames []string `json:"tag_names"` |
|
|
|
TargetKind string `json:"target_kind"` |
|
|
|
} |
|
|
|
|
|
|
|
func (q *Queries) SelectTargetsByTags(ctx context.Context, arg SelectTargetsByTagsParams) ([]string, error) { |
|
|
|
rows, err := q.db.QueryContext(ctx, selectTargetsByTags, pq.Array(arg.TagNames), arg.TargetKind) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
defer rows.Close() |
|
|
|
items := []string{} |
|
|
|
for rows.Next() { |
|
|
|
var target_id string |
|
|
|
if err := rows.Scan(&target_id); err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
items = append(items, target_id) |
|
|
|
} |
|
|
|
if err := rows.Close(); err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if err := rows.Err(); err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return items, nil |
|
|
|
} |
|
|
|
|
|
|
|
const setTag = `-- name: SetTag :exec |
|
|
|
INSERT INTO common_tag (tag, target_kind, target_id) |
|
|
|
VALUES ( |
|
|
@ -233,3 +283,20 @@ func (q *Queries) SetTag(ctx context.Context, arg SetTagParams) error { |
|
|
|
_, err := q.db.ExecContext(ctx, setTag, arg.Tag, arg.TargetKind, arg.TargetID) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
const setTags = `-- name: SetTags :exec |
|
|
|
INSERT INTO common_tag (tag, target_kind, target_id) |
|
|
|
SELECT unnest($1::TEXT[]), $2::TEXT as target_kind, $3::TEXT as target_id |
|
|
|
ON CONFLICT DO NOTHING |
|
|
|
` |
|
|
|
|
|
|
|
type SetTagsParams struct { |
|
|
|
Tags []string `json:"tags"` |
|
|
|
TargetKind string `json:"target_kind"` |
|
|
|
TargetID string `json:"target_id"` |
|
|
|
} |
|
|
|
|
|
|
|
func (q *Queries) SetTags(ctx context.Context, arg SetTagsParams) error { |
|
|
|
_, err := q.db.ExecContext(ctx, setTags, pq.Array(arg.Tags), arg.TargetKind, arg.TargetID) |
|
|
|
return err |
|
|
|
} |