2022-09-08 05:00:41 -07:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"emperror.dev/errors"
|
2023-04-03 19:11:03 -07:00
|
|
|
"github.com/jackc/pgx/v5"
|
2022-09-08 05:00:41 -07:00
|
|
|
"github.com/rs/xid"
|
|
|
|
)
|
|
|
|
|
2023-01-30 15:50:17 -08:00
|
|
|
func (db *DB) SetUserNamesPronouns(ctx context.Context, tx pgx.Tx, userID xid.ID, names []FieldEntry, pronouns []PronounEntry) (err error) {
|
2023-03-11 16:31:10 -08:00
|
|
|
sql, args, err := sq.Update("users").Set("names", names).Set("pronouns", pronouns).Where("id = ?", userID).ToSql()
|
2022-09-08 05:00:41 -07:00
|
|
|
if err != nil {
|
2023-03-11 16:31:10 -08:00
|
|
|
return errors.Wrap(err, "building sql")
|
2022-09-08 05:00:41 -07:00
|
|
|
}
|
|
|
|
|
2023-03-11 16:31:10 -08:00
|
|
|
_, err = tx.Exec(ctx, sql, args...)
|
2022-09-20 03:55:00 -07:00
|
|
|
if err != nil {
|
2023-03-11 16:31:10 -08:00
|
|
|
return errors.Wrap(err, "executing query")
|
2022-09-20 03:55:00 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2023-01-14 08:33:18 -08:00
|
|
|
|
2023-03-11 16:31:10 -08:00
|
|
|
func (db *DB) SetMemberNamesPronouns(ctx context.Context, tx pgx.Tx, memberID xid.ID, names []FieldEntry, pronouns []PronounEntry) (err error) {
|
|
|
|
sql, args, err := sq.Update("members").Set("names", names).Set("pronouns", pronouns).Where("id = ?", memberID).ToSql()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "building sql")
|
2023-01-14 08:33:18 -08:00
|
|
|
}
|
|
|
|
|
2023-03-11 16:31:10 -08:00
|
|
|
_, err = tx.Exec(ctx, sql, args...)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "executing query")
|
2023-01-14 08:33:18 -08:00
|
|
|
}
|
2023-03-11 16:31:10 -08:00
|
|
|
return nil
|
2023-01-14 08:33:18 -08:00
|
|
|
}
|