pronounsfu/backend/db/queries/queries.member.sql.go

804 lines
32 KiB
Go

// Code generated by pggen. DO NOT EDIT.
package queries
import (
"context"
"fmt"
"github.com/jackc/pgconn"
"github.com/jackc/pgtype"
"github.com/jackc/pgx/v4"
)
// Querier is a typesafe Go interface backed by SQL queries.
//
// Methods ending with Batch enqueue a query to run later in a pgx.Batch. After
// calling SendBatch on pgx.Conn, pgxpool.Pool, or pgx.Tx, use the Scan methods
// to parse the results.
type Querier interface {
GetMemberByID(ctx context.Context, id string) (GetMemberByIDRow, error)
// GetMemberByIDBatch enqueues a GetMemberByID query into batch to be executed
// later by the batch.
GetMemberByIDBatch(batch genericBatch, id string)
// GetMemberByIDScan scans the result of an executed GetMemberByIDBatch query.
GetMemberByIDScan(results pgx.BatchResults) (GetMemberByIDRow, error)
GetMemberByName(ctx context.Context, userID string, memberRef string) (GetMemberByNameRow, error)
// GetMemberByNameBatch enqueues a GetMemberByName query into batch to be executed
// later by the batch.
GetMemberByNameBatch(batch genericBatch, userID string, memberRef string)
// GetMemberByNameScan scans the result of an executed GetMemberByNameBatch query.
GetMemberByNameScan(results pgx.BatchResults) (GetMemberByNameRow, error)
GetMembers(ctx context.Context, userID string) ([]GetMembersRow, error)
// GetMembersBatch enqueues a GetMembers query into batch to be executed
// later by the batch.
GetMembersBatch(batch genericBatch, userID string)
// GetMembersScan scans the result of an executed GetMembersBatch query.
GetMembersScan(results pgx.BatchResults) ([]GetMembersRow, error)
UpdateMemberNamesPronouns(ctx context.Context, params UpdateMemberNamesPronounsParams) (UpdateMemberNamesPronounsRow, error)
// UpdateMemberNamesPronounsBatch enqueues a UpdateMemberNamesPronouns query into batch to be executed
// later by the batch.
UpdateMemberNamesPronounsBatch(batch genericBatch, params UpdateMemberNamesPronounsParams)
// UpdateMemberNamesPronounsScan scans the result of an executed UpdateMemberNamesPronounsBatch query.
UpdateMemberNamesPronounsScan(results pgx.BatchResults) (UpdateMemberNamesPronounsRow, error)
GetMemberFields(ctx context.Context, memberID string) ([]GetMemberFieldsRow, error)
// GetMemberFieldsBatch enqueues a GetMemberFields query into batch to be executed
// later by the batch.
GetMemberFieldsBatch(batch genericBatch, memberID string)
// GetMemberFieldsScan scans the result of an executed GetMemberFieldsBatch query.
GetMemberFieldsScan(results pgx.BatchResults) ([]GetMemberFieldsRow, error)
InsertMemberField(ctx context.Context, params InsertMemberFieldParams) (InsertMemberFieldRow, error)
// InsertMemberFieldBatch enqueues a InsertMemberField query into batch to be executed
// later by the batch.
InsertMemberFieldBatch(batch genericBatch, params InsertMemberFieldParams)
// InsertMemberFieldScan scans the result of an executed InsertMemberFieldBatch query.
InsertMemberFieldScan(results pgx.BatchResults) (InsertMemberFieldRow, error)
GetUserByID(ctx context.Context, id string) (GetUserByIDRow, error)
// GetUserByIDBatch enqueues a GetUserByID query into batch to be executed
// later by the batch.
GetUserByIDBatch(batch genericBatch, id string)
// GetUserByIDScan scans the result of an executed GetUserByIDBatch query.
GetUserByIDScan(results pgx.BatchResults) (GetUserByIDRow, error)
GetUserByUsername(ctx context.Context, username string) (GetUserByUsernameRow, error)
// GetUserByUsernameBatch enqueues a GetUserByUsername query into batch to be executed
// later by the batch.
GetUserByUsernameBatch(batch genericBatch, username string)
// GetUserByUsernameScan scans the result of an executed GetUserByUsernameBatch query.
GetUserByUsernameScan(results pgx.BatchResults) (GetUserByUsernameRow, error)
UpdateUserNamesPronouns(ctx context.Context, params UpdateUserNamesPronounsParams) (UpdateUserNamesPronounsRow, error)
// UpdateUserNamesPronounsBatch enqueues a UpdateUserNamesPronouns query into batch to be executed
// later by the batch.
UpdateUserNamesPronounsBatch(batch genericBatch, params UpdateUserNamesPronounsParams)
// UpdateUserNamesPronounsScan scans the result of an executed UpdateUserNamesPronounsBatch query.
UpdateUserNamesPronounsScan(results pgx.BatchResults) (UpdateUserNamesPronounsRow, error)
GetUserFields(ctx context.Context, userID string) ([]GetUserFieldsRow, error)
// GetUserFieldsBatch enqueues a GetUserFields query into batch to be executed
// later by the batch.
GetUserFieldsBatch(batch genericBatch, userID string)
// GetUserFieldsScan scans the result of an executed GetUserFieldsBatch query.
GetUserFieldsScan(results pgx.BatchResults) ([]GetUserFieldsRow, error)
InsertUserField(ctx context.Context, params InsertUserFieldParams) (InsertUserFieldRow, error)
// InsertUserFieldBatch enqueues a InsertUserField query into batch to be executed
// later by the batch.
InsertUserFieldBatch(batch genericBatch, params InsertUserFieldParams)
// InsertUserFieldScan scans the result of an executed InsertUserFieldBatch query.
InsertUserFieldScan(results pgx.BatchResults) (InsertUserFieldRow, error)
}
type DBQuerier struct {
conn genericConn // underlying Postgres transport to use
types *typeResolver // resolve types by name
}
var _ Querier = &DBQuerier{}
// genericConn is a connection to a Postgres database. This is usually backed by
// *pgx.Conn, pgx.Tx, or *pgxpool.Pool.
type genericConn interface {
// Query executes sql with args. If there is an error the returned Rows will
// be returned in an error state. So it is allowed to ignore the error
// returned from Query and handle it in Rows.
Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
// QueryRow is a convenience wrapper over Query. Any error that occurs while
// querying is deferred until calling Scan on the returned Row. That Row will
// error with pgx.ErrNoRows if no rows are returned.
QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
// Exec executes sql. sql can be either a prepared statement name or an SQL
// string. arguments should be referenced positionally from the sql string
// as $1, $2, etc.
Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
}
// genericBatch batches queries to send in a single network request to a
// Postgres server. This is usually backed by *pgx.Batch.
type genericBatch interface {
// Queue queues a query to batch b. query can be an SQL query or the name of a
// prepared statement. See Queue on *pgx.Batch.
Queue(query string, arguments ...interface{})
}
// NewQuerier creates a DBQuerier that implements Querier. conn is typically
// *pgx.Conn, pgx.Tx, or *pgxpool.Pool.
func NewQuerier(conn genericConn) *DBQuerier {
return NewQuerierConfig(conn, QuerierConfig{})
}
type QuerierConfig struct {
// DataTypes contains pgtype.Value to use for encoding and decoding instead
// of pggen-generated pgtype.ValueTranscoder.
//
// If OIDs are available for an input parameter type and all of its
// transitive dependencies, pggen will use the binary encoding format for
// the input parameter.
DataTypes []pgtype.DataType
}
// NewQuerierConfig creates a DBQuerier that implements Querier with the given
// config. conn is typically *pgx.Conn, pgx.Tx, or *pgxpool.Pool.
func NewQuerierConfig(conn genericConn, cfg QuerierConfig) *DBQuerier {
return &DBQuerier{conn: conn, types: newTypeResolver(cfg.DataTypes)}
}
// WithTx creates a new DBQuerier that uses the transaction to run all queries.
func (q *DBQuerier) WithTx(tx pgx.Tx) (*DBQuerier, error) {
return &DBQuerier{conn: tx}, nil
}
// preparer is any Postgres connection transport that provides a way to prepare
// a statement, most commonly *pgx.Conn.
type preparer interface {
Prepare(ctx context.Context, name, sql string) (sd *pgconn.StatementDescription, err error)
}
// PrepareAllQueries executes a PREPARE statement for all pggen generated SQL
// queries in querier files. Typical usage is as the AfterConnect callback
// for pgxpool.Config
//
// pgx will use the prepared statement if available. Calling PrepareAllQueries
// is an optional optimization to avoid a network round-trip the first time pgx
// runs a query if pgx statement caching is enabled.
func PrepareAllQueries(ctx context.Context, p preparer) error {
if _, err := p.Prepare(ctx, getMemberByIDSQL, getMemberByIDSQL); err != nil {
return fmt.Errorf("prepare query 'GetMemberByID': %w", err)
}
if _, err := p.Prepare(ctx, getMemberByNameSQL, getMemberByNameSQL); err != nil {
return fmt.Errorf("prepare query 'GetMemberByName': %w", err)
}
if _, err := p.Prepare(ctx, getMembersSQL, getMembersSQL); err != nil {
return fmt.Errorf("prepare query 'GetMembers': %w", err)
}
if _, err := p.Prepare(ctx, updateMemberNamesPronounsSQL, updateMemberNamesPronounsSQL); err != nil {
return fmt.Errorf("prepare query 'UpdateMemberNamesPronouns': %w", err)
}
if _, err := p.Prepare(ctx, getMemberFieldsSQL, getMemberFieldsSQL); err != nil {
return fmt.Errorf("prepare query 'GetMemberFields': %w", err)
}
if _, err := p.Prepare(ctx, insertMemberFieldSQL, insertMemberFieldSQL); err != nil {
return fmt.Errorf("prepare query 'InsertMemberField': %w", err)
}
if _, err := p.Prepare(ctx, getUserByIDSQL, getUserByIDSQL); err != nil {
return fmt.Errorf("prepare query 'GetUserByID': %w", err)
}
if _, err := p.Prepare(ctx, getUserByUsernameSQL, getUserByUsernameSQL); err != nil {
return fmt.Errorf("prepare query 'GetUserByUsername': %w", err)
}
if _, err := p.Prepare(ctx, updateUserNamesPronounsSQL, updateUserNamesPronounsSQL); err != nil {
return fmt.Errorf("prepare query 'UpdateUserNamesPronouns': %w", err)
}
if _, err := p.Prepare(ctx, getUserFieldsSQL, getUserFieldsSQL); err != nil {
return fmt.Errorf("prepare query 'GetUserFields': %w", err)
}
if _, err := p.Prepare(ctx, insertUserFieldSQL, insertUserFieldSQL); err != nil {
return fmt.Errorf("prepare query 'InsertUserField': %w", err)
}
return nil
}
// FieldEntry represents the Postgres composite type "field_entry".
type FieldEntry struct {
Value *string `json:"value"`
Status *int32 `json:"status"`
}
// PronounEntry represents the Postgres composite type "pronoun_entry".
type PronounEntry struct {
Value *string `json:"value"`
DisplayValue *string `json:"display_value"`
Status *int32 `json:"status"`
}
// typeResolver looks up the pgtype.ValueTranscoder by Postgres type name.
type typeResolver struct {
connInfo *pgtype.ConnInfo // types by Postgres type name
}
func newTypeResolver(types []pgtype.DataType) *typeResolver {
ci := pgtype.NewConnInfo()
for _, typ := range types {
if txt, ok := typ.Value.(textPreferrer); ok && typ.OID != unknownOID {
typ.Value = txt.ValueTranscoder
}
ci.RegisterDataType(typ)
}
return &typeResolver{connInfo: ci}
}
// findValue find the OID, and pgtype.ValueTranscoder for a Postgres type name.
func (tr *typeResolver) findValue(name string) (uint32, pgtype.ValueTranscoder, bool) {
typ, ok := tr.connInfo.DataTypeForName(name)
if !ok {
return 0, nil, false
}
v := pgtype.NewValue(typ.Value)
return typ.OID, v.(pgtype.ValueTranscoder), true
}
// setValue sets the value of a ValueTranscoder to a value that should always
// work and panics if it fails.
func (tr *typeResolver) setValue(vt pgtype.ValueTranscoder, val interface{}) pgtype.ValueTranscoder {
if err := vt.Set(val); err != nil {
panic(fmt.Sprintf("set ValueTranscoder %T to %+v: %s", vt, val, err))
}
return vt
}
type compositeField struct {
name string // name of the field
typeName string // Postgres type name
defaultVal pgtype.ValueTranscoder // default value to use
}
func (tr *typeResolver) newCompositeValue(name string, fields ...compositeField) pgtype.ValueTranscoder {
if _, val, ok := tr.findValue(name); ok {
return val
}
fs := make([]pgtype.CompositeTypeField, len(fields))
vals := make([]pgtype.ValueTranscoder, len(fields))
isBinaryOk := true
for i, field := range fields {
oid, val, ok := tr.findValue(field.typeName)
if !ok {
oid = unknownOID
val = field.defaultVal
}
isBinaryOk = isBinaryOk && oid != unknownOID
fs[i] = pgtype.CompositeTypeField{Name: field.name, OID: oid}
vals[i] = val
}
// Okay to ignore error because it's only thrown when the number of field
// names does not equal the number of ValueTranscoders.
typ, _ := pgtype.NewCompositeTypeValues(name, fs, vals)
if !isBinaryOk {
return textPreferrer{ValueTranscoder: typ, typeName: name}
}
return typ
}
func (tr *typeResolver) newArrayValue(name, elemName string, defaultVal func() pgtype.ValueTranscoder) pgtype.ValueTranscoder {
if _, val, ok := tr.findValue(name); ok {
return val
}
elemOID, elemVal, ok := tr.findValue(elemName)
elemValFunc := func() pgtype.ValueTranscoder {
return pgtype.NewValue(elemVal).(pgtype.ValueTranscoder)
}
if !ok {
elemOID = unknownOID
elemValFunc = defaultVal
}
typ := pgtype.NewArrayType(name, elemOID, elemValFunc)
if elemOID == unknownOID {
return textPreferrer{ValueTranscoder: typ, typeName: name}
}
return typ
}
// newFieldEntry creates a new pgtype.ValueTranscoder for the Postgres
// composite type 'field_entry'.
func (tr *typeResolver) newFieldEntry() pgtype.ValueTranscoder {
return tr.newCompositeValue(
"field_entry",
compositeField{name: "value", typeName: "text", defaultVal: &pgtype.Text{}},
compositeField{name: "status", typeName: "int4", defaultVal: &pgtype.Int4{}},
)
}
// newFieldEntryRaw returns all composite fields for the Postgres composite
// type 'field_entry' as a slice of interface{} to encode query parameters.
func (tr *typeResolver) newFieldEntryRaw(v FieldEntry) []interface{} {
return []interface{}{
v.Value,
v.Status,
}
}
// newPronounEntry creates a new pgtype.ValueTranscoder for the Postgres
// composite type 'pronoun_entry'.
func (tr *typeResolver) newPronounEntry() pgtype.ValueTranscoder {
return tr.newCompositeValue(
"pronoun_entry",
compositeField{name: "value", typeName: "text", defaultVal: &pgtype.Text{}},
compositeField{name: "display_value", typeName: "text", defaultVal: &pgtype.Text{}},
compositeField{name: "status", typeName: "int4", defaultVal: &pgtype.Int4{}},
)
}
// newPronounEntryRaw returns all composite fields for the Postgres composite
// type 'pronoun_entry' as a slice of interface{} to encode query parameters.
func (tr *typeResolver) newPronounEntryRaw(v PronounEntry) []interface{} {
return []interface{}{
v.Value,
v.DisplayValue,
v.Status,
}
}
// newFieldEntryArray creates a new pgtype.ValueTranscoder for the Postgres
// '_field_entry' array type.
func (tr *typeResolver) newFieldEntryArray() pgtype.ValueTranscoder {
return tr.newArrayValue("_field_entry", "field_entry", tr.newFieldEntry)
}
// newFieldEntryArrayInit creates an initialized pgtype.ValueTranscoder for the
// Postgres array type '_field_entry' to encode query parameters.
func (tr *typeResolver) newFieldEntryArrayInit(ps []FieldEntry) pgtype.ValueTranscoder {
dec := tr.newFieldEntryArray()
if err := dec.Set(tr.newFieldEntryArrayRaw(ps)); err != nil {
panic("encode []FieldEntry: " + err.Error()) // should always succeed
}
return textPreferrer{ValueTranscoder: dec, typeName: "_field_entry"}
}
// newFieldEntryArrayRaw returns all elements for the Postgres array type '_field_entry'
// as a slice of interface{} for use with the pgtype.Value Set method.
func (tr *typeResolver) newFieldEntryArrayRaw(vs []FieldEntry) []interface{} {
elems := make([]interface{}, len(vs))
for i, v := range vs {
elems[i] = tr.newFieldEntryRaw(v)
}
return elems
}
// newPronounEntryArray creates a new pgtype.ValueTranscoder for the Postgres
// '_pronoun_entry' array type.
func (tr *typeResolver) newPronounEntryArray() pgtype.ValueTranscoder {
return tr.newArrayValue("_pronoun_entry", "pronoun_entry", tr.newPronounEntry)
}
// newPronounEntryArrayInit creates an initialized pgtype.ValueTranscoder for the
// Postgres array type '_pronoun_entry' to encode query parameters.
func (tr *typeResolver) newPronounEntryArrayInit(ps []PronounEntry) pgtype.ValueTranscoder {
dec := tr.newPronounEntryArray()
if err := dec.Set(tr.newPronounEntryArrayRaw(ps)); err != nil {
panic("encode []PronounEntry: " + err.Error()) // should always succeed
}
return textPreferrer{ValueTranscoder: dec, typeName: "_pronoun_entry"}
}
// newPronounEntryArrayRaw returns all elements for the Postgres array type '_pronoun_entry'
// as a slice of interface{} for use with the pgtype.Value Set method.
func (tr *typeResolver) newPronounEntryArrayRaw(vs []PronounEntry) []interface{} {
elems := make([]interface{}, len(vs))
for i, v := range vs {
elems[i] = tr.newPronounEntryRaw(v)
}
return elems
}
const getMemberByIDSQL = `SELECT * FROM members
WHERE id = $1;`
type GetMemberByIDRow struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Name string `json:"name"`
Bio *string `json:"bio"`
AvatarUrls []string `json:"avatar_urls"`
Links []string `json:"links"`
DisplayName *string `json:"display_name"`
Names []FieldEntry `json:"names"`
Pronouns []PronounEntry `json:"pronouns"`
}
// GetMemberByID implements Querier.GetMemberByID.
func (q *DBQuerier) GetMemberByID(ctx context.Context, id string) (GetMemberByIDRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "GetMemberByID")
row := q.conn.QueryRow(ctx, getMemberByIDSQL, id)
var item GetMemberByIDRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.UserID, &item.Name, &item.Bio, &item.AvatarUrls, &item.Links, &item.DisplayName, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("query GetMemberByID: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign GetMemberByID row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign GetMemberByID row: %w", err)
}
return item, nil
}
// GetMemberByIDBatch implements Querier.GetMemberByIDBatch.
func (q *DBQuerier) GetMemberByIDBatch(batch genericBatch, id string) {
batch.Queue(getMemberByIDSQL, id)
}
// GetMemberByIDScan implements Querier.GetMemberByIDScan.
func (q *DBQuerier) GetMemberByIDScan(results pgx.BatchResults) (GetMemberByIDRow, error) {
row := results.QueryRow()
var item GetMemberByIDRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.UserID, &item.Name, &item.Bio, &item.AvatarUrls, &item.Links, &item.DisplayName, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("scan GetMemberByIDBatch row: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign GetMemberByID row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign GetMemberByID row: %w", err)
}
return item, nil
}
const getMemberByNameSQL = `SELECT * FROM members
WHERE user_id = $1 AND (
id = $2
OR name = $2
);`
type GetMemberByNameRow struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Name string `json:"name"`
Bio *string `json:"bio"`
AvatarUrls []string `json:"avatar_urls"`
Links []string `json:"links"`
DisplayName *string `json:"display_name"`
Names []FieldEntry `json:"names"`
Pronouns []PronounEntry `json:"pronouns"`
}
// GetMemberByName implements Querier.GetMemberByName.
func (q *DBQuerier) GetMemberByName(ctx context.Context, userID string, memberRef string) (GetMemberByNameRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "GetMemberByName")
row := q.conn.QueryRow(ctx, getMemberByNameSQL, userID, memberRef)
var item GetMemberByNameRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.UserID, &item.Name, &item.Bio, &item.AvatarUrls, &item.Links, &item.DisplayName, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("query GetMemberByName: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign GetMemberByName row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign GetMemberByName row: %w", err)
}
return item, nil
}
// GetMemberByNameBatch implements Querier.GetMemberByNameBatch.
func (q *DBQuerier) GetMemberByNameBatch(batch genericBatch, userID string, memberRef string) {
batch.Queue(getMemberByNameSQL, userID, memberRef)
}
// GetMemberByNameScan implements Querier.GetMemberByNameScan.
func (q *DBQuerier) GetMemberByNameScan(results pgx.BatchResults) (GetMemberByNameRow, error) {
row := results.QueryRow()
var item GetMemberByNameRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.UserID, &item.Name, &item.Bio, &item.AvatarUrls, &item.Links, &item.DisplayName, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("scan GetMemberByNameBatch row: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign GetMemberByName row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign GetMemberByName row: %w", err)
}
return item, nil
}
const getMembersSQL = `SELECT * FROM members
WHERE user_id = $1
ORDER BY name, id;`
type GetMembersRow struct {
ID *string `json:"id"`
UserID *string `json:"user_id"`
Name *string `json:"name"`
Bio *string `json:"bio"`
AvatarUrls []string `json:"avatar_urls"`
Links []string `json:"links"`
DisplayName *string `json:"display_name"`
Names []FieldEntry `json:"names"`
Pronouns []PronounEntry `json:"pronouns"`
}
// GetMembers implements Querier.GetMembers.
func (q *DBQuerier) GetMembers(ctx context.Context, userID string) ([]GetMembersRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "GetMembers")
rows, err := q.conn.Query(ctx, getMembersSQL, userID)
if err != nil {
return nil, fmt.Errorf("query GetMembers: %w", err)
}
defer rows.Close()
items := []GetMembersRow{}
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
for rows.Next() {
var item GetMembersRow
if err := rows.Scan(&item.ID, &item.UserID, &item.Name, &item.Bio, &item.AvatarUrls, &item.Links, &item.DisplayName, namesArray, pronounsArray); err != nil {
return nil, fmt.Errorf("scan GetMembers row: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return nil, fmt.Errorf("assign GetMembers row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return nil, fmt.Errorf("assign GetMembers row: %w", err)
}
items = append(items, item)
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("close GetMembers rows: %w", err)
}
return items, err
}
// GetMembersBatch implements Querier.GetMembersBatch.
func (q *DBQuerier) GetMembersBatch(batch genericBatch, userID string) {
batch.Queue(getMembersSQL, userID)
}
// GetMembersScan implements Querier.GetMembersScan.
func (q *DBQuerier) GetMembersScan(results pgx.BatchResults) ([]GetMembersRow, error) {
rows, err := results.Query()
if err != nil {
return nil, fmt.Errorf("query GetMembersBatch: %w", err)
}
defer rows.Close()
items := []GetMembersRow{}
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
for rows.Next() {
var item GetMembersRow
if err := rows.Scan(&item.ID, &item.UserID, &item.Name, &item.Bio, &item.AvatarUrls, &item.Links, &item.DisplayName, namesArray, pronounsArray); err != nil {
return nil, fmt.Errorf("scan GetMembersBatch row: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return nil, fmt.Errorf("assign GetMembers row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return nil, fmt.Errorf("assign GetMembers row: %w", err)
}
items = append(items, item)
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("close GetMembersBatch rows: %w", err)
}
return items, err
}
const updateMemberNamesPronounsSQL = `UPDATE members SET
names = $1,
pronouns = $2
WHERE id = $3
RETURNING *;`
type UpdateMemberNamesPronounsParams struct {
Names []FieldEntry
Pronouns []PronounEntry
ID string
}
type UpdateMemberNamesPronounsRow struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Name string `json:"name"`
Bio *string `json:"bio"`
AvatarUrls []string `json:"avatar_urls"`
Links []string `json:"links"`
DisplayName *string `json:"display_name"`
Names []FieldEntry `json:"names"`
Pronouns []PronounEntry `json:"pronouns"`
}
// UpdateMemberNamesPronouns implements Querier.UpdateMemberNamesPronouns.
func (q *DBQuerier) UpdateMemberNamesPronouns(ctx context.Context, params UpdateMemberNamesPronounsParams) (UpdateMemberNamesPronounsRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "UpdateMemberNamesPronouns")
row := q.conn.QueryRow(ctx, updateMemberNamesPronounsSQL, q.types.newFieldEntryArrayInit(params.Names), q.types.newPronounEntryArrayInit(params.Pronouns), params.ID)
var item UpdateMemberNamesPronounsRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.UserID, &item.Name, &item.Bio, &item.AvatarUrls, &item.Links, &item.DisplayName, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("query UpdateMemberNamesPronouns: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign UpdateMemberNamesPronouns row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign UpdateMemberNamesPronouns row: %w", err)
}
return item, nil
}
// UpdateMemberNamesPronounsBatch implements Querier.UpdateMemberNamesPronounsBatch.
func (q *DBQuerier) UpdateMemberNamesPronounsBatch(batch genericBatch, params UpdateMemberNamesPronounsParams) {
batch.Queue(updateMemberNamesPronounsSQL, q.types.newFieldEntryArrayInit(params.Names), q.types.newPronounEntryArrayInit(params.Pronouns), params.ID)
}
// UpdateMemberNamesPronounsScan implements Querier.UpdateMemberNamesPronounsScan.
func (q *DBQuerier) UpdateMemberNamesPronounsScan(results pgx.BatchResults) (UpdateMemberNamesPronounsRow, error) {
row := results.QueryRow()
var item UpdateMemberNamesPronounsRow
namesArray := q.types.newFieldEntryArray()
pronounsArray := q.types.newPronounEntryArray()
if err := row.Scan(&item.ID, &item.UserID, &item.Name, &item.Bio, &item.AvatarUrls, &item.Links, &item.DisplayName, namesArray, pronounsArray); err != nil {
return item, fmt.Errorf("scan UpdateMemberNamesPronounsBatch row: %w", err)
}
if err := namesArray.AssignTo(&item.Names); err != nil {
return item, fmt.Errorf("assign UpdateMemberNamesPronouns row: %w", err)
}
if err := pronounsArray.AssignTo(&item.Pronouns); err != nil {
return item, fmt.Errorf("assign UpdateMemberNamesPronouns row: %w", err)
}
return item, nil
}
const getMemberFieldsSQL = `SELECT * FROM member_fields WHERE member_id = $1 ORDER BY id ASC;`
type GetMemberFieldsRow struct {
MemberID *string `json:"member_id"`
ID *int `json:"id"`
Name *string `json:"name"`
Entries []FieldEntry `json:"entries"`
}
// GetMemberFields implements Querier.GetMemberFields.
func (q *DBQuerier) GetMemberFields(ctx context.Context, memberID string) ([]GetMemberFieldsRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "GetMemberFields")
rows, err := q.conn.Query(ctx, getMemberFieldsSQL, memberID)
if err != nil {
return nil, fmt.Errorf("query GetMemberFields: %w", err)
}
defer rows.Close()
items := []GetMemberFieldsRow{}
entriesArray := q.types.newFieldEntryArray()
for rows.Next() {
var item GetMemberFieldsRow
if err := rows.Scan(&item.MemberID, &item.ID, &item.Name, entriesArray); err != nil {
return nil, fmt.Errorf("scan GetMemberFields row: %w", err)
}
if err := entriesArray.AssignTo(&item.Entries); err != nil {
return nil, fmt.Errorf("assign GetMemberFields row: %w", err)
}
items = append(items, item)
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("close GetMemberFields rows: %w", err)
}
return items, err
}
// GetMemberFieldsBatch implements Querier.GetMemberFieldsBatch.
func (q *DBQuerier) GetMemberFieldsBatch(batch genericBatch, memberID string) {
batch.Queue(getMemberFieldsSQL, memberID)
}
// GetMemberFieldsScan implements Querier.GetMemberFieldsScan.
func (q *DBQuerier) GetMemberFieldsScan(results pgx.BatchResults) ([]GetMemberFieldsRow, error) {
rows, err := results.Query()
if err != nil {
return nil, fmt.Errorf("query GetMemberFieldsBatch: %w", err)
}
defer rows.Close()
items := []GetMemberFieldsRow{}
entriesArray := q.types.newFieldEntryArray()
for rows.Next() {
var item GetMemberFieldsRow
if err := rows.Scan(&item.MemberID, &item.ID, &item.Name, entriesArray); err != nil {
return nil, fmt.Errorf("scan GetMemberFieldsBatch row: %w", err)
}
if err := entriesArray.AssignTo(&item.Entries); err != nil {
return nil, fmt.Errorf("assign GetMemberFields row: %w", err)
}
items = append(items, item)
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("close GetMemberFieldsBatch rows: %w", err)
}
return items, err
}
const insertMemberFieldSQL = `INSERT INTO member_fields
(member_id, name, entries) VALUES
($1, $2, $3)
RETURNING *;`
type InsertMemberFieldParams struct {
MemberID string
Name string
Entries []FieldEntry
}
type InsertMemberFieldRow struct {
MemberID string `json:"member_id"`
ID int `json:"id"`
Name string `json:"name"`
Entries []FieldEntry `json:"entries"`
}
// InsertMemberField implements Querier.InsertMemberField.
func (q *DBQuerier) InsertMemberField(ctx context.Context, params InsertMemberFieldParams) (InsertMemberFieldRow, error) {
ctx = context.WithValue(ctx, "pggen_query_name", "InsertMemberField")
row := q.conn.QueryRow(ctx, insertMemberFieldSQL, params.MemberID, params.Name, q.types.newFieldEntryArrayInit(params.Entries))
var item InsertMemberFieldRow
entriesArray := q.types.newFieldEntryArray()
if err := row.Scan(&item.MemberID, &item.ID, &item.Name, entriesArray); err != nil {
return item, fmt.Errorf("query InsertMemberField: %w", err)
}
if err := entriesArray.AssignTo(&item.Entries); err != nil {
return item, fmt.Errorf("assign InsertMemberField row: %w", err)
}
return item, nil
}
// InsertMemberFieldBatch implements Querier.InsertMemberFieldBatch.
func (q *DBQuerier) InsertMemberFieldBatch(batch genericBatch, params InsertMemberFieldParams) {
batch.Queue(insertMemberFieldSQL, params.MemberID, params.Name, q.types.newFieldEntryArrayInit(params.Entries))
}
// InsertMemberFieldScan implements Querier.InsertMemberFieldScan.
func (q *DBQuerier) InsertMemberFieldScan(results pgx.BatchResults) (InsertMemberFieldRow, error) {
row := results.QueryRow()
var item InsertMemberFieldRow
entriesArray := q.types.newFieldEntryArray()
if err := row.Scan(&item.MemberID, &item.ID, &item.Name, entriesArray); err != nil {
return item, fmt.Errorf("scan InsertMemberFieldBatch row: %w", err)
}
if err := entriesArray.AssignTo(&item.Entries); err != nil {
return item, fmt.Errorf("assign InsertMemberField row: %w", err)
}
return item, nil
}
// textPreferrer wraps a pgtype.ValueTranscoder and sets the preferred encoding
// format to text instead binary (the default). pggen uses the text format
// when the OID is unknownOID because the binary format requires the OID.
// Typically occurs if the results from QueryAllDataTypes aren't passed to
// NewQuerierConfig.
type textPreferrer struct {
pgtype.ValueTranscoder
typeName string
}
// PreferredParamFormat implements pgtype.ParamFormatPreferrer.
func (t textPreferrer) PreferredParamFormat() int16 { return pgtype.TextFormatCode }
func (t textPreferrer) NewTypeValue() pgtype.Value {
return textPreferrer{ValueTranscoder: pgtype.NewValue(t.ValueTranscoder).(pgtype.ValueTranscoder), typeName: t.typeName}
}
func (t textPreferrer) TypeName() string {
return t.typeName
}
// unknownOID means we don't know the OID for a type. This is okay for decoding
// because pgx call DecodeText or DecodeBinary without requiring the OID. For
// encoding parameters, pggen uses textPreferrer if the OID is unknown.
const unknownOID = 0