You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
302 lines
7.7 KiB
302 lines
7.7 KiB
// Code generated by sqlc. DO NOT EDIT.
|
|
// source: tags.sql
|
|
|
|
package psqlcore
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/lib/pq"
|
|
)
|
|
|
|
const clearTag = `-- name: ClearTag :exec
|
|
DELETE FROM common_tag
|
|
WHERE tag=$1::TEXT
|
|
AND target_kind=$2::TEXT
|
|
AND target_id=$3::TEXT
|
|
`
|
|
|
|
type ClearTagParams struct {
|
|
Tag string `json:"tag"`
|
|
TargetKind string `json:"target_kind"`
|
|
TargetID string `json:"target_id"`
|
|
}
|
|
|
|
func (q *Queries) ClearTag(ctx context.Context, arg ClearTagParams) error {
|
|
_, err := q.db.ExecContext(ctx, clearTag, arg.Tag, arg.TargetKind, arg.TargetID)
|
|
return err
|
|
}
|
|
|
|
const clearTagsByTarget = `-- name: ClearTagsByTarget :exec
|
|
DELETE FROM common_tag
|
|
WHERE target_kind=$1::TEXT
|
|
AND target_id=$2::TEXT
|
|
`
|
|
|
|
type ClearTagsByTargetParams struct {
|
|
TargetKind string `json:"target_kind"`
|
|
TargetID string `json:"target_id"`
|
|
}
|
|
|
|
func (q *Queries) ClearTagsByTarget(ctx context.Context, arg ClearTagsByTargetParams) error {
|
|
_, err := q.db.ExecContext(ctx, clearTagsByTarget, arg.TargetKind, arg.TargetID)
|
|
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 ORDER BY tag
|
|
`
|
|
|
|
func (q *Queries) SelectDistinctTags(ctx context.Context) ([]string, error) {
|
|
rows, err := q.db.QueryContext(ctx, selectDistinctTags)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []string{}
|
|
for rows.Next() {
|
|
var tag string
|
|
if err := rows.Scan(&tag); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, tag)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const selectDistinctTagsLike = `-- name: SelectDistinctTagsLike :many
|
|
SELECT DISTINCT tag FROM common_tag WHERE tag LIKE $1::text ORDER BY tag
|
|
`
|
|
|
|
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
|
|
}
|
|
defer rows.Close()
|
|
items := []string{}
|
|
for rows.Next() {
|
|
var tag string
|
|
if err := rows.Scan(&tag); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, tag)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const selectTagsByTag = `-- name: SelectTagsByTag :many
|
|
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) {
|
|
rows, err := q.db.QueryContext(ctx, selectTagsByTag, tagName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []CommonTag{}
|
|
for rows.Next() {
|
|
var i CommonTag
|
|
if err := rows.Scan(&i.Tag, &i.TargetKind, &i.TargetID); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const selectTagsByTags = `-- name: SelectTagsByTags :many
|
|
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) {
|
|
rows, err := q.db.QueryContext(ctx, selectTagsByTags, pq.Array(tagNames))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []CommonTag{}
|
|
for rows.Next() {
|
|
var i CommonTag
|
|
if err := rows.Scan(&i.Tag, &i.TargetKind, &i.TargetID); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const selectTagsByTarget = `-- name: SelectTagsByTarget :many
|
|
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"`
|
|
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.TargetID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []CommonTag{}
|
|
for rows.Next() {
|
|
var i CommonTag
|
|
if err := rows.Scan(&i.Tag, &i.TargetKind, &i.TargetID); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const selectTagsByTargets = `-- name: SelectTagsByTargets :many
|
|
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"`
|
|
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.TargetIds))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []CommonTag{}
|
|
for rows.Next() {
|
|
var i CommonTag
|
|
if err := rows.Scan(&i.Tag, &i.TargetKind, &i.TargetID); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
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 (
|
|
$1::TEXT, $2::TEXT, $3::TEXT
|
|
)
|
|
ON CONFLICT DO NOTHING
|
|
`
|
|
|
|
type SetTagParams struct {
|
|
Tag string `json:"tag"`
|
|
TargetKind string `json:"target_kind"`
|
|
TargetID string `json:"target_id"`
|
|
}
|
|
|
|
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
|
|
}
|