2022-09-08 14:00:41 +02:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"emperror.dev/errors"
|
|
|
|
"github.com/jackc/pgx/v4"
|
|
|
|
"github.com/rs/xid"
|
|
|
|
)
|
|
|
|
|
2023-01-31 00:50:17 +01:00
|
|
|
func (db *DB) SetUserNamesPronouns(ctx context.Context, tx pgx.Tx, userID xid.ID, names []FieldEntry, pronouns []PronounEntry) (err error) {
|
2023-03-12 01:31:10 +01:00
|
|
|
sql, args, err := sq.Update("users").Set("names", names).Set("pronouns", pronouns).Where("id = ?", userID).ToSql()
|
2022-09-08 14:00:41 +02:00
|
|
|
if err != nil {
|
2023-03-12 01:31:10 +01:00
|
|
|
return errors.Wrap(err, "building sql")
|
2022-09-08 14:00:41 +02:00
|
|
|
}
|
|
|
|
|
2023-03-12 01:31:10 +01:00
|
|
|
_, err = tx.Exec(ctx, sql, args...)
|
2022-09-20 12:55:00 +02:00
|
|
|
if err != nil {
|
2023-03-12 01:31:10 +01:00
|
|
|
return errors.Wrap(err, "executing query")
|
2022-09-20 12:55:00 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2023-01-14 17:33:18 +01:00
|
|
|
|
2023-03-12 01:31:10 +01: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 17:33:18 +01:00
|
|
|
}
|
|
|
|
|
2023-03-12 01:31:10 +01:00
|
|
|
_, err = tx.Exec(ctx, sql, args...)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "executing query")
|
2023-01-14 17:33:18 +01:00
|
|
|
}
|
2023-03-12 01:31:10 +01:00
|
|
|
return nil
|
2023-01-14 17:33:18 +01:00
|
|
|
}
|