pronounss/backend/db/queries/queries.user.sql.go
2023-01-04 22:41:29 +01:00

310 lines
12 KiB
Go

// Code generated by pggen. DO NOT EDIT.
package queries
import (
"context"
"fmt"
"github.com/jackc/pgx/v4"
)
const getUserByIDSQL = `SELECT * FROM users WHERE id = $1;`
type GetUserByIDRow struct {
ID string `json:"id"`
Username string `json:"username"`
DisplayName *string `json:"display_name"`
Bio *string `json:"bio"`
AvatarUrls []string `json:"avatar_urls"`
Links []string `json:"links"`
Discord *string `json:"discord"`
DiscordUsername *string `json:"discord_username"`
MaxInvites int32 `json:"max_invites"`
Names []FieldEntry `json:"names"`
Pronouns []PronounEntry `json:"pronouns"`
}
// GetUserByID implements Querier.GetUserByID.
func (q *DBQuerier) GetUserByID(ctx context.Context, id string) (GetUserByIDRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "GetUserByID")
row := q.conn.QueryRow(ctx, getUserByIDSQL, id)
var item GetUserByIDRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.Username, &item.DisplayName, &item.Bio, &item.AvatarUrls, &item.Links, &item.Discord, &item.DiscordUsername, &item.MaxInvites, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("query GetUserByID: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign GetUserByID row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign GetUserByID row: %w", err)
}
return item, nil
}
// GetUserByIDBatch implements Querier.GetUserByIDBatch.
func (q *DBQuerier) GetUserByIDBatch(batch genericBatch, id string) {
batch.Queue(getUserByIDSQL, id)
}
// GetUserByIDScan implements Querier.GetUserByIDScan.
func (q *DBQuerier) GetUserByIDScan(results pgx.BatchResults) (GetUserByIDRow, error) {
row := results.QueryRow()
var item GetUserByIDRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.Username, &item.DisplayName, &item.Bio, &item.AvatarUrls, &item.Links, &item.Discord, &item.DiscordUsername, &item.MaxInvites, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("scan GetUserByIDBatch row: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign GetUserByID row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign GetUserByID row: %w", err)
}
return item, nil
}
const getUserByUsernameSQL = `SELECT * FROM users WHERE username = $1;`
type GetUserByUsernameRow struct {
ID string `json:"id"`
Username string `json:"username"`
DisplayName *string `json:"display_name"`
Bio *string `json:"bio"`
AvatarUrls []string `json:"avatar_urls"`
Links []string `json:"links"`
Discord *string `json:"discord"`
DiscordUsername *string `json:"discord_username"`
MaxInvites int32 `json:"max_invites"`
Names []FieldEntry `json:"names"`
Pronouns []PronounEntry `json:"pronouns"`
}
// GetUserByUsername implements Querier.GetUserByUsername.
func (q *DBQuerier) GetUserByUsername(ctx context.Context, username string) (GetUserByUsernameRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "GetUserByUsername")
row := q.conn.QueryRow(ctx, getUserByUsernameSQL, username)
var item GetUserByUsernameRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.Username, &item.DisplayName, &item.Bio, &item.AvatarUrls, &item.Links, &item.Discord, &item.DiscordUsername, &item.MaxInvites, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("query GetUserByUsername: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign GetUserByUsername row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign GetUserByUsername row: %w", err)
}
return item, nil
}
// GetUserByUsernameBatch implements Querier.GetUserByUsernameBatch.
func (q *DBQuerier) GetUserByUsernameBatch(batch genericBatch, username string) {
batch.Queue(getUserByUsernameSQL, username)
}
// GetUserByUsernameScan implements Querier.GetUserByUsernameScan.
func (q *DBQuerier) GetUserByUsernameScan(results pgx.BatchResults) (GetUserByUsernameRow, error) {
row := results.QueryRow()
var item GetUserByUsernameRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.Username, &item.DisplayName, &item.Bio, &item.AvatarUrls, &item.Links, &item.Discord, &item.DiscordUsername, &item.MaxInvites, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("scan GetUserByUsernameBatch row: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign GetUserByUsername row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign GetUserByUsername row: %w", err)
}
return item, nil
}
const updateUserNamesPronounsSQL = `UPDATE users SET
names = $1,
pronouns = $2
WHERE id = $3
RETURNING *;`
type UpdateUserNamesPronounsParams struct {
Names []FieldEntry
Pronouns []PronounEntry
ID string
}
type UpdateUserNamesPronounsRow struct {
ID string `json:"id"`
Username string `json:"username"`
DisplayName *string `json:"display_name"`
Bio *string `json:"bio"`
AvatarUrls []string `json:"avatar_urls"`
Links []string `json:"links"`
Discord *string `json:"discord"`
DiscordUsername *string `json:"discord_username"`
MaxInvites int32 `json:"max_invites"`
Names []FieldEntry `json:"names"`
Pronouns []PronounEntry `json:"pronouns"`
}
// UpdateUserNamesPronouns implements Querier.UpdateUserNamesPronouns.
func (q *DBQuerier) UpdateUserNamesPronouns(ctx context.Context, params UpdateUserNamesPronounsParams) (UpdateUserNamesPronounsRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "UpdateUserNamesPronouns")
row := q.conn.QueryRow(ctx, updateUserNamesPronounsSQL, q.types.newFieldEntryArrayInit(params.Names), q.types.newPronounEntryArrayInit(params.Pronouns), params.ID)
var item UpdateUserNamesPronounsRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.Username, &item.DisplayName, &item.Bio, &item.AvatarUrls, &item.Links, &item.Discord, &item.DiscordUsername, &item.MaxInvites, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("query UpdateUserNamesPronouns: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign UpdateUserNamesPronouns row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign UpdateUserNamesPronouns row: %w", err)
}
return item, nil
}
// UpdateUserNamesPronounsBatch implements Querier.UpdateUserNamesPronounsBatch.
func (q *DBQuerier) UpdateUserNamesPronounsBatch(batch genericBatch, params UpdateUserNamesPronounsParams) {
batch.Queue(updateUserNamesPronounsSQL, q.types.newFieldEntryArrayInit(params.Names), q.types.newPronounEntryArrayInit(params.Pronouns), params.ID)
}
// UpdateUserNamesPronounsScan implements Querier.UpdateUserNamesPronounsScan.
func (q *DBQuerier) UpdateUserNamesPronounsScan(results pgx.BatchResults) (UpdateUserNamesPronounsRow, error) {
row := results.QueryRow()
var item UpdateUserNamesPronounsRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.Username, &item.DisplayName, &item.Bio, &item.AvatarUrls, &item.Links, &item.Discord, &item.DiscordUsername, &item.MaxInvites, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("scan UpdateUserNamesPronounsBatch row: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign UpdateUserNamesPronouns row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign UpdateUserNamesPronouns row: %w", err)
}
return item, nil
}
const getUserFieldsSQL = `SELECT * FROM user_fields WHERE user_id = $1 ORDER BY id ASC;`
type GetUserFieldsRow struct {
UserID *string `json:"user_id"`
ID *int `json:"id"`
Name *string `json:"name"`
Entries []FieldEntry `json:"entries"`
}
// GetUserFields implements Querier.GetUserFields.
func (q *DBQuerier) GetUserFields(ctx context.Context, userID string) ([]GetUserFieldsRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "GetUserFields")
rows, err := q.conn.Query(ctx, getUserFieldsSQL, userID)
if err != nil {
return nil, fmt.Errorf("query GetUserFields: %w", err)
}
defer rows.Close()
items := []GetUserFieldsRow{}
entriesArray := q.types.newFieldEntryArray()
for rows.Next() {
var item GetUserFieldsRow
if err := rows.Scan(&item.UserID, &item.ID, &item.Name, entriesArray); err != nil {
return nil, fmt.Errorf("scan GetUserFields row: %w", err)
}
if err := entriesArray.AssignTo(&item.Entries); err != nil {
return nil, fmt.Errorf("assign GetUserFields row: %w", err)
}
items = append(items, item)
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("close GetUserFields rows: %w", err)
}
return items, err
}
// GetUserFieldsBatch implements Querier.GetUserFieldsBatch.
func (q *DBQuerier) GetUserFieldsBatch(batch genericBatch, userID string) {
batch.Queue(getUserFieldsSQL, userID)
}
// GetUserFieldsScan implements Querier.GetUserFieldsScan.
func (q *DBQuerier) GetUserFieldsScan(results pgx.BatchResults) ([]GetUserFieldsRow, error) {
rows, err := results.Query()
if err != nil {
return nil, fmt.Errorf("query GetUserFieldsBatch: %w", err)
}
defer rows.Close()
items := []GetUserFieldsRow{}
entriesArray := q.types.newFieldEntryArray()
for rows.Next() {
var item GetUserFieldsRow
if err := rows.Scan(&item.UserID, &item.ID, &item.Name, entriesArray); err != nil {
return nil, fmt.Errorf("scan GetUserFieldsBatch row: %w", err)
}
if err := entriesArray.AssignTo(&item.Entries); err != nil {
return nil, fmt.Errorf("assign GetUserFields row: %w", err)
}
items = append(items, item)
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("close GetUserFieldsBatch rows: %w", err)
}
return items, err
}
const insertUserFieldSQL = `INSERT INTO user_fields
(user_id, name, entries) VALUES
($1, $2, $3)
RETURNING *;`
type InsertUserFieldParams struct {
UserID string
Name string
Entries []FieldEntry
}
type InsertUserFieldRow struct {
UserID string `json:"user_id"`
ID int `json:"id"`
Name string `json:"name"`
Entries []FieldEntry `json:"entries"`
}
// InsertUserField implements Querier.InsertUserField.
func (q *DBQuerier) InsertUserField(ctx context.Context, params InsertUserFieldParams) (InsertUserFieldRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "InsertUserField")
row := q.conn.QueryRow(ctx, insertUserFieldSQL, params.UserID, params.Name, q.types.newFieldEntryArrayInit(params.Entries))
var item InsertUserFieldRow
entriesArray := q.types.newFieldEntryArray()
if err := row.Scan(&item.UserID, &item.ID, &item.Name, entriesArray); err != nil {
return item, fmt.Errorf("query InsertUserField: %w", err)
}
if err := entriesArray.AssignTo(&item.Entries); err != nil {
return item, fmt.Errorf("assign InsertUserField row: %w", err)
}
return item, nil
}
// InsertUserFieldBatch implements Querier.InsertUserFieldBatch.
func (q *DBQuerier) InsertUserFieldBatch(batch genericBatch, params InsertUserFieldParams) {
batch.Queue(insertUserFieldSQL, params.UserID, params.Name, q.types.newFieldEntryArrayInit(params.Entries))
}
// InsertUserFieldScan implements Querier.InsertUserFieldScan.
func (q *DBQuerier) InsertUserFieldScan(results pgx.BatchResults) (InsertUserFieldRow, error) {
row := results.QueryRow()
var item InsertUserFieldRow
entriesArray := q.types.newFieldEntryArray()
if err := row.Scan(&item.UserID, &item.ID, &item.Name, entriesArray); err != nil {
return item, fmt.Errorf("scan InsertUserFieldBatch row: %w", err)
}
if err := entriesArray.AssignTo(&item.Entries); err != nil {
return item, fmt.Errorf("assign InsertUserField row: %w", err)
}
return item, nil
}