This commit is contained in:
@@ -10,6 +10,53 @@ import (
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
const deleteStory = `-- name: DeleteStory :exec
|
||||
DELETE FROM story WHERE id=$1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteStory(ctx context.Context, id string) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteStory, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertStory = `-- name: InsertStory :exec
|
||||
INSERT INTO story (id, author, name, category, open, listed, sort_by_fictional_date, created_date, fictional_date, updated_date)
|
||||
VALUES (
|
||||
$1::text, $2::text, $3::text, $4::text,
|
||||
$5::boolean, $6::boolean, $7::boolean,
|
||||
$8::timestamp, $9::timestamp, $10::timestamp
|
||||
)
|
||||
`
|
||||
|
||||
type InsertStoryParams struct {
|
||||
ID string `json:"id"`
|
||||
Author string `json:"author"`
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"`
|
||||
Open bool `json:"open"`
|
||||
Listed bool `json:"listed"`
|
||||
SortByFictionalDate bool `json:"sort_by_fictional_date"`
|
||||
CreatedDate time.Time `json:"created_date"`
|
||||
FictionalDate time.Time `json:"fictional_date"`
|
||||
UpdatedDate time.Time `json:"updated_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertStory(ctx context.Context, arg InsertStoryParams) error {
|
||||
_, err := q.db.ExecContext(ctx, insertStory,
|
||||
arg.ID,
|
||||
arg.Author,
|
||||
arg.Name,
|
||||
arg.Category,
|
||||
arg.Open,
|
||||
arg.Listed,
|
||||
arg.SortByFictionalDate,
|
||||
arg.CreatedDate,
|
||||
arg.FictionalDate,
|
||||
arg.UpdatedDate,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const selectStories = `-- name: SelectStories :many
|
||||
SELECT id, author, name, category, open, listed, sort_by_fictional_date, created_date, fictional_date, updated_date FROM story
|
||||
WHERE ($1::bool = false OR id = ANY($2::text[]))
|
||||
@@ -111,3 +158,43 @@ func (q *Queries) SelectStory(ctx context.Context, id string) (Story, error) {
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateStory = `-- name: UpdateStory :exec
|
||||
UPDATE story
|
||||
SET name=$1,
|
||||
category=$2,
|
||||
author=$3,
|
||||
open=$4,
|
||||
listed=$5,
|
||||
fictional_date=$6,
|
||||
updated_date=$7,
|
||||
sort_by_fictional_date=$8
|
||||
WHERE id=$9
|
||||
`
|
||||
|
||||
type UpdateStoryParams struct {
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"`
|
||||
Author string `json:"author"`
|
||||
Open bool `json:"open"`
|
||||
Listed bool `json:"listed"`
|
||||
FictionalDate time.Time `json:"fictional_date"`
|
||||
UpdatedDate time.Time `json:"updated_date"`
|
||||
SortByFictionalDate bool `json:"sort_by_fictional_date"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateStory(ctx context.Context, arg UpdateStoryParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateStory,
|
||||
arg.Name,
|
||||
arg.Category,
|
||||
arg.Author,
|
||||
arg.Open,
|
||||
arg.Listed,
|
||||
arg.FictionalDate,
|
||||
arg.UpdatedDate,
|
||||
arg.SortByFictionalDate,
|
||||
arg.ID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user