// Code generated by sqlc. DO NOT EDIT. // source: stories.sql package psqlcore import ( "context" "time" "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[])) AND ($3::bool = false OR name = $4::text) AND ($5::bool = false OR fictional_date >= $6::timestamp) AND ($7::bool = false OR fictional_date <= $8::timestamp) 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 ` type SelectStoriesParams struct { FilterID bool `json:"filter_id"` Ids []string `json:"ids"` FilterAuthor bool `json:"filter_author"` Author string `json:"author"` FilterEarlistFictionalDate bool `json:"filter_earlist_fictional_date"` EarliestFictionalDate time.Time `json:"earliest_fictional_date"` FilterLastestFictionalDate bool `json:"filter_lastest_fictional_date"` LatestFictionalDate time.Time `json:"latest_fictional_date"` FilterCategory bool `json:"filter_category"` Category string `json:"category"` FilterOpen bool `json:"filter_open"` Open bool `json:"open"` FilterUnlisted bool `json:"filter_unlisted"` Unlisted bool `json:"unlisted"` LimitSize int32 `json:"limit_size"` } func (q *Queries) SelectStories(ctx context.Context, arg SelectStoriesParams) ([]Story, error) { rows, err := q.db.QueryContext(ctx, selectStories, arg.FilterID, pq.Array(arg.Ids), arg.FilterAuthor, arg.Author, arg.FilterEarlistFictionalDate, arg.EarliestFictionalDate, arg.FilterLastestFictionalDate, arg.LatestFictionalDate, arg.FilterCategory, arg.Category, arg.FilterOpen, arg.Open, arg.FilterUnlisted, arg.Unlisted, arg.LimitSize, ) if err != nil { return nil, err } defer rows.Close() items := []Story{} for rows.Next() { var i Story if err := rows.Scan( &i.ID, &i.Author, &i.Name, &i.Category, &i.Open, &i.Listed, &i.SortByFictionalDate, &i.CreatedDate, &i.FictionalDate, &i.UpdatedDate, ); 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 selectStory = `-- name: SelectStory :one SELECT id, author, name, category, open, listed, sort_by_fictional_date, created_date, fictional_date, updated_date FROM story WHERE id = $1 LIMIT 1 ` func (q *Queries) SelectStory(ctx context.Context, id string) (Story, error) { row := q.db.QueryRowContext(ctx, selectStory, id) var i Story err := row.Scan( &i.ID, &i.Author, &i.Name, &i.Category, &i.Open, &i.Listed, &i.SortByFictionalDate, &i.CreatedDate, &i.FictionalDate, &i.UpdatedDate, ) 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 }