feat: all the work with db now here, for some time it dups ../api dir
This commit is contained in:
parent
e239c0ca04
commit
eda59c68d3
3 changed files with 1010 additions and 0 deletions
32
modules/backend/db/db.go
Normal file
32
modules/backend/db/db.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
266
modules/backend/db/models.go
Normal file
266
modules/backend/db/models.go
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type ReleaseSeasonT string
|
||||
|
||||
const (
|
||||
ReleaseSeasonTWinter ReleaseSeasonT = "winter"
|
||||
ReleaseSeasonTSpring ReleaseSeasonT = "spring"
|
||||
ReleaseSeasonTSummer ReleaseSeasonT = "summer"
|
||||
ReleaseSeasonTFall ReleaseSeasonT = "fall"
|
||||
)
|
||||
|
||||
func (e *ReleaseSeasonT) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = ReleaseSeasonT(s)
|
||||
case string:
|
||||
*e = ReleaseSeasonT(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for ReleaseSeasonT: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullReleaseSeasonT struct {
|
||||
ReleaseSeasonT ReleaseSeasonT `json:"release_season_t"`
|
||||
Valid bool `json:"valid"` // Valid is true if ReleaseSeasonT is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullReleaseSeasonT) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.ReleaseSeasonT, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.ReleaseSeasonT.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullReleaseSeasonT) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.ReleaseSeasonT), nil
|
||||
}
|
||||
|
||||
type StorageTypeT string
|
||||
|
||||
const (
|
||||
StorageTypeTLocal StorageTypeT = "local"
|
||||
StorageTypeTS3 StorageTypeT = "s3"
|
||||
)
|
||||
|
||||
func (e *StorageTypeT) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = StorageTypeT(s)
|
||||
case string:
|
||||
*e = StorageTypeT(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for StorageTypeT: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullStorageTypeT struct {
|
||||
StorageTypeT StorageTypeT `json:"storage_type_t"`
|
||||
Valid bool `json:"valid"` // Valid is true if StorageTypeT is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullStorageTypeT) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.StorageTypeT, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.StorageTypeT.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullStorageTypeT) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.StorageTypeT), nil
|
||||
}
|
||||
|
||||
type TitleStatusT string
|
||||
|
||||
const (
|
||||
TitleStatusTFinished TitleStatusT = "finished"
|
||||
TitleStatusTOngoing TitleStatusT = "ongoing"
|
||||
TitleStatusTPlanned TitleStatusT = "planned"
|
||||
)
|
||||
|
||||
func (e *TitleStatusT) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = TitleStatusT(s)
|
||||
case string:
|
||||
*e = TitleStatusT(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for TitleStatusT: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullTitleStatusT struct {
|
||||
TitleStatusT TitleStatusT `json:"title_status_t"`
|
||||
Valid bool `json:"valid"` // Valid is true if TitleStatusT is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullTitleStatusT) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.TitleStatusT, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.TitleStatusT.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullTitleStatusT) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.TitleStatusT), nil
|
||||
}
|
||||
|
||||
type UsertitleStatusT string
|
||||
|
||||
const (
|
||||
UsertitleStatusTFinished UsertitleStatusT = "finished"
|
||||
UsertitleStatusTPlanned UsertitleStatusT = "planned"
|
||||
UsertitleStatusTDropped UsertitleStatusT = "dropped"
|
||||
UsertitleStatusTInProgress UsertitleStatusT = "in-progress"
|
||||
)
|
||||
|
||||
func (e *UsertitleStatusT) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = UsertitleStatusT(s)
|
||||
case string:
|
||||
*e = UsertitleStatusT(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for UsertitleStatusT: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullUsertitleStatusT struct {
|
||||
UsertitleStatusT UsertitleStatusT `json:"usertitle_status_t"`
|
||||
Valid bool `json:"valid"` // Valid is true if UsertitleStatusT is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullUsertitleStatusT) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.UsertitleStatusT, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.UsertitleStatusT.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullUsertitleStatusT) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.UsertitleStatusT), nil
|
||||
}
|
||||
|
||||
type Images struct {
|
||||
ImageID int32 `db:"image_id" json:"image_id"`
|
||||
StorageType StorageTypeT `db:"storage_type" json:"storage_type"`
|
||||
ImagePath string `db:"image_path" json:"image_path"`
|
||||
}
|
||||
|
||||
type Providers struct {
|
||||
ProviderID int32 `db:"provider_id" json:"provider_id"`
|
||||
ProviderName string `db:"provider_name" json:"provider_name"`
|
||||
}
|
||||
|
||||
type Reviews struct {
|
||||
ReviewID int32 `db:"review_id" json:"review_id"`
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
ImageIds []int32 `db:"image_ids" json:"image_ids"`
|
||||
ReviewText string `db:"review_text" json:"review_text"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
type Signals struct {
|
||||
SignalID int32 `db:"signal_id" json:"signal_id"`
|
||||
RawData []byte `db:"raw_data" json:"raw_data"`
|
||||
ProviderID int32 `db:"provider_id" json:"provider_id"`
|
||||
Dirty bool `db:"dirty" json:"dirty"`
|
||||
}
|
||||
|
||||
type Studios struct {
|
||||
StudioID int32 `db:"studio_id" json:"studio_id"`
|
||||
StudioName pgtype.Text `db:"studio_name" json:"studio_name"`
|
||||
IllustID pgtype.Int4 `db:"illust_id" json:"illust_id"`
|
||||
StudioDesc pgtype.Text `db:"studio_desc" json:"studio_desc"`
|
||||
}
|
||||
|
||||
type Tags struct {
|
||||
TagID int32 `db:"tag_id" json:"tag_id"`
|
||||
TagNames []byte `db:"tag_names" json:"tag_names"`
|
||||
}
|
||||
|
||||
type TitleTags struct {
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
TagID int32 `db:"tag_id" json:"tag_id"`
|
||||
}
|
||||
|
||||
type Titles struct {
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
TitleNames []byte `db:"title_names" json:"title_names"`
|
||||
StudioID int32 `db:"studio_id" json:"studio_id"`
|
||||
PosterID pgtype.Int4 `db:"poster_id" json:"poster_id"`
|
||||
SignalIds []int32 `db:"signal_ids" json:"signal_ids"`
|
||||
TitleStatus TitleStatusT `db:"title_status" json:"title_status"`
|
||||
Rating pgtype.Float8 `db:"rating" json:"rating"`
|
||||
RatingCount pgtype.Int4 `db:"rating_count" json:"rating_count"`
|
||||
ReleaseYear pgtype.Int4 `db:"release_year" json:"release_year"`
|
||||
ReleaseSeason NullReleaseSeasonT `db:"release_season" json:"release_season"`
|
||||
Season pgtype.Int4 `db:"season" json:"season"`
|
||||
EpisodesAired pgtype.Int4 `db:"episodes_aired" json:"episodes_aired"`
|
||||
EpisodesAll pgtype.Int4 `db:"episodes_all" json:"episodes_all"`
|
||||
EpisodesLen []byte `db:"episodes_len" json:"episodes_len"`
|
||||
}
|
||||
|
||||
type Users struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Passhash string `db:"passhash" json:"passhash"`
|
||||
Mail pgtype.Text `db:"mail" json:"mail"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
type Usertitles struct {
|
||||
UsertitleID int32 `db:"usertitle_id" json:"usertitle_id"`
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Status UsertitleStatusT `db:"status" json:"status"`
|
||||
Rate pgtype.Int4 `db:"rate" json:"rate"`
|
||||
ReviewID pgtype.Int4 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
712
modules/backend/db/query.sql.go
Normal file
712
modules/backend/db/query.sql.go
Normal file
|
|
@ -0,0 +1,712 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: query.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createImage = `-- name: CreateImage :one
|
||||
INSERT INTO images (storage_type, image_path)
|
||||
VALUES ($1, $2)
|
||||
RETURNING image_id, storage_type, image_path
|
||||
`
|
||||
|
||||
type CreateImageParams struct {
|
||||
StorageType StorageTypeT `db:"storage_type" json:"storage_type"`
|
||||
ImagePath string `db:"image_path" json:"image_path"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateImage(ctx context.Context, arg CreateImageParams) (Images, error) {
|
||||
row := q.db.QueryRow(ctx, createImage, arg.StorageType, arg.ImagePath)
|
||||
var i Images
|
||||
err := row.Scan(&i.ImageID, &i.StorageType, &i.ImagePath)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createReview = `-- name: CreateReview :one
|
||||
INSERT INTO reviews (user_id, title_id, image_ids, review_text, creation_date)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
`
|
||||
|
||||
type CreateReviewParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
ImageIds []int32 `db:"image_ids" json:"image_ids"`
|
||||
ReviewText string `db:"review_text" json:"review_text"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateReview(ctx context.Context, arg CreateReviewParams) (Reviews, error) {
|
||||
row := q.db.QueryRow(ctx, createReview,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
arg.ImageIds,
|
||||
arg.ReviewText,
|
||||
arg.CreationDate,
|
||||
)
|
||||
var i Reviews
|
||||
err := row.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Passhash string `db:"passhash" json:"passhash"`
|
||||
Mail pgtype.Text `db:"mail" json:"mail"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
type CreateUserRow struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, createUser,
|
||||
arg.AvatarID,
|
||||
arg.Passhash,
|
||||
arg.Mail,
|
||||
arg.Nickname,
|
||||
arg.DispName,
|
||||
arg.UserDesc,
|
||||
arg.CreationDate,
|
||||
)
|
||||
var i CreateUserRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createUserTitle = `-- name: CreateUserTitle :one
|
||||
INSERT INTO usertitles (user_id, title_id, status, rate, review_id)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING usertitle_id, user_id, title_id, status, rate, review_id
|
||||
`
|
||||
|
||||
type CreateUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Status UsertitleStatusT `db:"status" json:"status"`
|
||||
Rate pgtype.Int4 `db:"rate" json:"rate"`
|
||||
ReviewID pgtype.Int4 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUserTitle(ctx context.Context, arg CreateUserTitleParams) (Usertitles, error) {
|
||||
row := q.db.QueryRow(ctx, createUserTitle,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
arg.Status,
|
||||
arg.Rate,
|
||||
arg.ReviewID,
|
||||
)
|
||||
var i Usertitles
|
||||
err := row.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteReview = `-- name: DeleteReview :exec
|
||||
DELETE FROM reviews
|
||||
WHERE review_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteReview(ctx context.Context, reviewID int32) error {
|
||||
_, err := q.db.Exec(ctx, deleteReview, reviewID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteUser = `-- name: DeleteUser :exec
|
||||
DELETE FROM users
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteUser(ctx context.Context, userID int32) error {
|
||||
_, err := q.db.Exec(ctx, deleteUser, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteUserTitle = `-- name: DeleteUserTitle :exec
|
||||
DELETE FROM usertitles
|
||||
WHERE user_id = $1 AND ($2::int IS NULL OR title_id = $2)
|
||||
`
|
||||
|
||||
type DeleteUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
Column2 int32 `db:"column_2" json:"column_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteUserTitle(ctx context.Context, arg DeleteUserTitleParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteUserTitle, arg.UserID, arg.Column2)
|
||||
return err
|
||||
}
|
||||
|
||||
const getImageByID = `-- name: GetImageByID :one
|
||||
SELECT image_id, storage_type, image_path
|
||||
FROM images
|
||||
WHERE image_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetImageByID(ctx context.Context, imageID int32) (Images, error) {
|
||||
row := q.db.QueryRow(ctx, getImageByID, imageID)
|
||||
var i Images
|
||||
err := row.Scan(&i.ImageID, &i.StorageType, &i.ImagePath)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getReviewByID = `-- name: GetReviewByID :one
|
||||
SELECT review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
FROM reviews
|
||||
WHERE review_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetReviewByID(ctx context.Context, reviewID int32) (Reviews, error) {
|
||||
row := q.db.QueryRow(ctx, getReviewByID, reviewID)
|
||||
var i Reviews
|
||||
err := row.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getTitleByID = `-- name: GetTitleByID :one
|
||||
SELECT title_id, title_names, studio_id, poster_id, signal_ids,
|
||||
title_status, rating, rating_count, release_year, release_season,
|
||||
season, episodes_aired, episodes_all, episodes_len
|
||||
FROM titles
|
||||
WHERE title_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetTitleByID(ctx context.Context, titleID int32) (Titles, error) {
|
||||
row := q.db.QueryRow(ctx, getTitleByID, titleID)
|
||||
var i Titles
|
||||
err := row.Scan(
|
||||
&i.TitleID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.SignalIds,
|
||||
&i.TitleStatus,
|
||||
&i.Rating,
|
||||
&i.RatingCount,
|
||||
&i.ReleaseYear,
|
||||
&i.ReleaseSeason,
|
||||
&i.Season,
|
||||
&i.EpisodesAired,
|
||||
&i.EpisodesAll,
|
||||
&i.EpisodesLen,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT user_id, avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date
|
||||
FROM users
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, userID int32) (Users, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByID, userID)
|
||||
var i Users
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Passhash,
|
||||
&i.Mail,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserTitle = `-- name: GetUserTitle :one
|
||||
SELECT usertitle_id, user_id, title_id, status, rate, review_id
|
||||
FROM usertitles
|
||||
WHERE user_id = $1 AND title_id = $2
|
||||
`
|
||||
|
||||
type GetUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserTitle(ctx context.Context, arg GetUserTitleParams) (Usertitles, error) {
|
||||
row := q.db.QueryRow(ctx, getUserTitle, arg.UserID, arg.TitleID)
|
||||
var i Usertitles
|
||||
err := row.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listReviewsByTitle = `-- name: ListReviewsByTitle :many
|
||||
SELECT review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
FROM reviews
|
||||
WHERE title_id = $1
|
||||
ORDER BY creation_date DESC
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
type ListReviewsByTitleParams struct {
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListReviewsByTitle(ctx context.Context, arg ListReviewsByTitleParams) ([]Reviews, error) {
|
||||
rows, err := q.db.Query(ctx, listReviewsByTitle, arg.TitleID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Reviews
|
||||
for rows.Next() {
|
||||
var i Reviews
|
||||
if err := rows.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listReviewsByUser = `-- name: ListReviewsByUser :many
|
||||
SELECT review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
FROM reviews
|
||||
WHERE user_id = $1
|
||||
ORDER BY creation_date DESC
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
type ListReviewsByUserParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListReviewsByUser(ctx context.Context, arg ListReviewsByUserParams) ([]Reviews, error) {
|
||||
rows, err := q.db.Query(ctx, listReviewsByUser, arg.UserID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Reviews
|
||||
for rows.Next() {
|
||||
var i Reviews
|
||||
if err := rows.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTags = `-- name: ListTags :many
|
||||
SELECT tag_id, tag_names
|
||||
FROM tags
|
||||
ORDER BY tag_id
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListTagsParams struct {
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTags(ctx context.Context, arg ListTagsParams) ([]Tags, error) {
|
||||
rows, err := q.db.Query(ctx, listTags, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Tags
|
||||
for rows.Next() {
|
||||
var i Tags
|
||||
if err := rows.Scan(&i.TagID, &i.TagNames); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTitles = `-- name: ListTitles :many
|
||||
SELECT title_id, title_names, studio_id, poster_id, signal_ids,
|
||||
title_status, rating, rating_count, release_year, release_season,
|
||||
season, episodes_aired, episodes_all, episodes_len
|
||||
FROM titles
|
||||
ORDER BY title_id
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListTitlesParams struct {
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTitles(ctx context.Context, arg ListTitlesParams) ([]Titles, error) {
|
||||
rows, err := q.db.Query(ctx, listTitles, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Titles
|
||||
for rows.Next() {
|
||||
var i Titles
|
||||
if err := rows.Scan(
|
||||
&i.TitleID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.SignalIds,
|
||||
&i.TitleStatus,
|
||||
&i.Rating,
|
||||
&i.RatingCount,
|
||||
&i.ReleaseYear,
|
||||
&i.ReleaseSeason,
|
||||
&i.Season,
|
||||
&i.EpisodesAired,
|
||||
&i.EpisodesAll,
|
||||
&i.EpisodesLen,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listUserTitles = `-- name: ListUserTitles :many
|
||||
SELECT usertitle_id, user_id, title_id, status, rate, review_id
|
||||
FROM usertitles
|
||||
WHERE user_id = $1
|
||||
ORDER BY usertitle_id
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
type ListUserTitlesParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListUserTitles(ctx context.Context, arg ListUserTitlesParams) ([]Usertitles, error) {
|
||||
rows, err := q.db.Query(ctx, listUserTitles, arg.UserID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Usertitles
|
||||
for rows.Next() {
|
||||
var i Usertitles
|
||||
if err := rows.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listUsers = `-- name: ListUsers :many
|
||||
SELECT user_id, avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date
|
||||
FROM users
|
||||
ORDER BY user_id
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListUsersParams struct {
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]Users, error) {
|
||||
rows, err := q.db.Query(ctx, listUsers, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Users
|
||||
for rows.Next() {
|
||||
var i Users
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Passhash,
|
||||
&i.Mail,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateReview = `-- name: UpdateReview :one
|
||||
UPDATE reviews
|
||||
SET
|
||||
image_ids = COALESCE($1, image_ids),
|
||||
review_text = COALESCE($2, review_text)
|
||||
WHERE review_id = $3
|
||||
RETURNING review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
`
|
||||
|
||||
type UpdateReviewParams struct {
|
||||
ImageIds []int32 `db:"image_ids" json:"image_ids"`
|
||||
ReviewText pgtype.Text `db:"review_text" json:"review_text"`
|
||||
ReviewID int32 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateReview(ctx context.Context, arg UpdateReviewParams) (Reviews, error) {
|
||||
row := q.db.QueryRow(ctx, updateReview, arg.ImageIds, arg.ReviewText, arg.ReviewID)
|
||||
var i Reviews
|
||||
err := row.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateTitle = `-- name: UpdateTitle :one
|
||||
UPDATE titles
|
||||
SET
|
||||
title_names = COALESCE($1, title_names),
|
||||
studio_id = COALESCE($2, studio_id),
|
||||
poster_id = COALESCE($3, poster_id),
|
||||
signal_ids = COALESCE($4, signal_ids),
|
||||
title_status = COALESCE($5, title_status),
|
||||
release_year = COALESCE($6, release_year),
|
||||
release_season = COALESCE($7, release_season),
|
||||
episodes_aired = COALESCE($8, episodes_aired),
|
||||
episodes_all = COALESCE($9, episodes_all),
|
||||
episodes_len = COALESCE($10, episodes_len)
|
||||
WHERE title_id = $11
|
||||
RETURNING title_id, title_names, studio_id, poster_id, signal_ids, title_status, rating, rating_count, release_year, release_season, season, episodes_aired, episodes_all, episodes_len
|
||||
`
|
||||
|
||||
type UpdateTitleParams struct {
|
||||
TitleNames []byte `db:"title_names" json:"title_names"`
|
||||
StudioID pgtype.Int4 `db:"studio_id" json:"studio_id"`
|
||||
PosterID pgtype.Int4 `db:"poster_id" json:"poster_id"`
|
||||
SignalIds []int32 `db:"signal_ids" json:"signal_ids"`
|
||||
TitleStatus NullTitleStatusT `db:"title_status" json:"title_status"`
|
||||
ReleaseYear pgtype.Int4 `db:"release_year" json:"release_year"`
|
||||
ReleaseSeason NullReleaseSeasonT `db:"release_season" json:"release_season"`
|
||||
EpisodesAired pgtype.Int4 `db:"episodes_aired" json:"episodes_aired"`
|
||||
EpisodesAll pgtype.Int4 `db:"episodes_all" json:"episodes_all"`
|
||||
EpisodesLen []byte `db:"episodes_len" json:"episodes_len"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateTitle(ctx context.Context, arg UpdateTitleParams) (Titles, error) {
|
||||
row := q.db.QueryRow(ctx, updateTitle,
|
||||
arg.TitleNames,
|
||||
arg.StudioID,
|
||||
arg.PosterID,
|
||||
arg.SignalIds,
|
||||
arg.TitleStatus,
|
||||
arg.ReleaseYear,
|
||||
arg.ReleaseSeason,
|
||||
arg.EpisodesAired,
|
||||
arg.EpisodesAll,
|
||||
arg.EpisodesLen,
|
||||
arg.TitleID,
|
||||
)
|
||||
var i Titles
|
||||
err := row.Scan(
|
||||
&i.TitleID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.SignalIds,
|
||||
&i.TitleStatus,
|
||||
&i.Rating,
|
||||
&i.RatingCount,
|
||||
&i.ReleaseYear,
|
||||
&i.ReleaseSeason,
|
||||
&i.Season,
|
||||
&i.EpisodesAired,
|
||||
&i.EpisodesAll,
|
||||
&i.EpisodesLen,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUser = `-- name: UpdateUser :one
|
||||
UPDATE users
|
||||
SET
|
||||
avatar_id = COALESCE($1, avatar_id),
|
||||
disp_name = COALESCE($2, disp_name),
|
||||
user_desc = COALESCE($3, user_desc)
|
||||
WHERE user_id = $4
|
||||
RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date
|
||||
`
|
||||
|
||||
type UpdateUserParams struct {
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
}
|
||||
|
||||
type UpdateUserRow struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateUser,
|
||||
arg.AvatarID,
|
||||
arg.DispName,
|
||||
arg.UserDesc,
|
||||
arg.UserID,
|
||||
)
|
||||
var i UpdateUserRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserTitle = `-- name: UpdateUserTitle :one
|
||||
UPDATE usertitles
|
||||
SET
|
||||
status = COALESCE($3, status),
|
||||
rate = COALESCE($4, rate),
|
||||
review_id = COALESCE($5, review_id)
|
||||
WHERE user_id = $1 AND title_id = $2
|
||||
RETURNING usertitle_id, user_id, title_id, status, rate, review_id
|
||||
`
|
||||
|
||||
type UpdateUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Status NullUsertitleStatusT `db:"status" json:"status"`
|
||||
Rate pgtype.Int4 `db:"rate" json:"rate"`
|
||||
ReviewID pgtype.Int4 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserTitle(ctx context.Context, arg UpdateUserTitleParams) (Usertitles, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserTitle,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
arg.Status,
|
||||
arg.Rate,
|
||||
arg.ReviewID,
|
||||
)
|
||||
var i Usertitles
|
||||
err := row.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue