add chapter repository to postgres.
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-03-26 23:50:33 +01:00
parent 525191a0f9
commit 663a95c70d
13 changed files with 420 additions and 5 deletions
@@ -80,6 +80,7 @@ WHERE ($1::bool = false OR keys && ($2::text[]))
AND ($3::bool = false OR date >= $4::timestamp)
AND ($5::bool = false OR date <= $6::timestamp)
AND ($7::bool = false OR author = $8::text)
ORDER BY date DESC
LIMIT $9::int
`
@@ -69,6 +69,7 @@ WHERE ($1::bool = false OR name = ANY($2::text[]))
AND ($3::bool = false OR logged = $4)
AND ($5::bool = false OR event_name = $6)
AND ($7::bool = false OR location_name = $8)
ORDER BY name
LIMIT $9::int
`
+177
View File
@@ -0,0 +1,177 @@
// Code generated by sqlc. DO NOT EDIT.
// source: chapters.sql
package psqlcore
import (
"context"
"time"
)
const deleteChapter = `-- name: DeleteChapter :exec
DELETE FROM story_chapter WHERE id=$1
`
func (q *Queries) DeleteChapter(ctx context.Context, id string) error {
_, err := q.db.ExecContext(ctx, deleteChapter, id)
return err
}
const deleteChaptersByStoryID = `-- name: DeleteChaptersByStoryID :exec
DELETE FROM story_chapter WHERE story_id=$1
`
func (q *Queries) DeleteChaptersByStoryID(ctx context.Context, storyID string) error {
_, err := q.db.ExecContext(ctx, deleteChaptersByStoryID, storyID)
return err
}
const insertChapter = `-- name: InsertChapter :exec
INSERT INTO story_chapter (id, story_id, title, author, source, created_date, fictional_date, edited_date, comment_mode, comments_locked)
VALUES (
$1::TEXT, $2::TEXT, $3::TEXT, $4::TEXT, $5::TEXT,
$6::TIMESTAMP, $7::TIMESTAMP, $8::TIMESTAMP,
$9::TEXT, $10::BOOLEAN
)
`
type InsertChapterParams struct {
ID string `json:"id"`
StoryID string `json:"story_id"`
Title string `json:"title"`
Author string `json:"author"`
Source string `json:"source"`
CreatedDate time.Time `json:"created_date"`
FictionalDate time.Time `json:"fictional_date"`
EditedDate time.Time `json:"edited_date"`
CommentMode string `json:"comment_mode"`
CommentsLocked bool `json:"comments_locked"`
}
func (q *Queries) InsertChapter(ctx context.Context, arg InsertChapterParams) error {
_, err := q.db.ExecContext(ctx, insertChapter,
arg.ID,
arg.StoryID,
arg.Title,
arg.Author,
arg.Source,
arg.CreatedDate,
arg.FictionalDate,
arg.EditedDate,
arg.CommentMode,
arg.CommentsLocked,
)
return err
}
const selectChapter = `-- name: SelectChapter :one
SELECT id, story_id, title, author, source, created_date, fictional_date, edited_date, comment_mode, comments_locked FROM story_chapter WHERE id=$1::TEXT LIMIT 1
`
func (q *Queries) SelectChapter(ctx context.Context, dollar_1 string) (StoryChapter, error) {
row := q.db.QueryRowContext(ctx, selectChapter, dollar_1)
var i StoryChapter
err := row.Scan(
&i.ID,
&i.StoryID,
&i.Title,
&i.Author,
&i.Source,
&i.CreatedDate,
&i.FictionalDate,
&i.EditedDate,
&i.CommentMode,
&i.CommentsLocked,
)
return i, err
}
const selectChapters = `-- name: SelectChapters :many
SELECT id, story_id, title, author, source, created_date, fictional_date, edited_date, comment_mode, comments_locked FROM story_chapter WHERE (sqlx.arg(story_id)::TEXT == '' OR story_id=$1::TEXT) ORDER BY created_date LIMIT $2::INT
`
type SelectChaptersParams struct {
StoryID string `json:"story_id"`
LimitSize int32 `json:"limit_size"`
}
func (q *Queries) SelectChapters(ctx context.Context, arg SelectChaptersParams) ([]StoryChapter, error) {
rows, err := q.db.QueryContext(ctx, selectChapters, arg.StoryID, arg.LimitSize)
if err != nil {
return nil, err
}
defer rows.Close()
items := []StoryChapter{}
for rows.Next() {
var i StoryChapter
if err := rows.Scan(
&i.ID,
&i.StoryID,
&i.Title,
&i.Author,
&i.Source,
&i.CreatedDate,
&i.FictionalDate,
&i.EditedDate,
&i.CommentMode,
&i.CommentsLocked,
); 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 updateChapter = `-- name: UpdateChapter :exec
UPDATE story_chapter
SET title=$1,
source=$2,
fictional_date=$3,
comment_mode=$4,
comments_locked=$5
WHERE id=$6
`
type UpdateChapterParams struct {
Title string `json:"title"`
Source string `json:"source"`
FictionalDate time.Time `json:"fictional_date"`
CommentMode string `json:"comment_mode"`
CommentsLocked bool `json:"comments_locked"`
ID string `json:"id"`
}
func (q *Queries) UpdateChapter(ctx context.Context, arg UpdateChapterParams) error {
_, err := q.db.ExecContext(ctx, updateChapter,
arg.Title,
arg.Source,
arg.FictionalDate,
arg.CommentMode,
arg.CommentsLocked,
arg.ID,
)
return err
}
const updateChapterStoryID = `-- name: UpdateChapterStoryID :exec
UPDATE story_chapter
SET story_id=$1::TEXT
WHERE id=$2
`
type UpdateChapterStoryIDParams struct {
StoryID string `json:"story_id"`
ID string `json:"id"`
}
func (q *Queries) UpdateChapterStoryID(ctx context.Context, arg UpdateChapterStoryIDParams) error {
_, err := q.db.ExecContext(ctx, updateChapterStoryID, arg.StoryID, arg.ID)
return err
}
+13
View File
@@ -60,3 +60,16 @@ type Story struct {
FictionalDate time.Time `json:"fictional_date"`
UpdatedDate time.Time `json:"updated_date"`
}
type StoryChapter struct {
ID string `json:"id"`
StoryID string `json:"story_id"`
Title string `json:"title"`
Author string `json:"author"`
Source string `json:"source"`
CreatedDate time.Time `json:"created_date"`
FictionalDate time.Time `json:"fictional_date"`
EditedDate time.Time `json:"edited_date"`
CommentMode string `json:"comment_mode"`
CommentsLocked bool `json:"comments_locked"`
}
@@ -66,6 +66,7 @@ WHERE ($1::bool = false OR id = ANY($2::text[]))
AND ($9::bool = false OR category = $10::text)
AND ($11::bool = false OR open = $12::bool)
AND ($13::bool = false OR unlisted = $14::bool)
ORDER BY updated_date
LIMIT $15::int
`