aboutsummaryrefslogtreecommitdiff
path: root/userapi/storage/postgres/profile_table.go
diff options
context:
space:
mode:
Diffstat (limited to 'userapi/storage/postgres/profile_table.go')
-rw-r--r--userapi/storage/postgres/profile_table.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/userapi/storage/postgres/profile_table.go b/userapi/storage/postgres/profile_table.go
index 9313864b..32a4b550 100644
--- a/userapi/storage/postgres/profile_table.go
+++ b/userapi/storage/postgres/profile_table.go
@@ -22,6 +22,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
+ "github.com/matrix-org/dendrite/userapi/storage/tables"
)
const profilesSchema = `
@@ -59,12 +60,13 @@ type profilesStatements struct {
selectProfilesBySearchStmt *sql.Stmt
}
-func (s *profilesStatements) prepare(db *sql.DB) (err error) {
- _, err = db.Exec(profilesSchema)
+func NewPostgresProfilesTable(db *sql.DB) (tables.ProfileTable, error) {
+ s := &profilesStatements{}
+ _, err := db.Exec(profilesSchema)
if err != nil {
- return
+ return nil, err
}
- return sqlutil.StatementList{
+ return s, sqlutil.StatementList{
{&s.insertProfileStmt, insertProfileSQL},
{&s.selectProfileByLocalpartStmt, selectProfileByLocalpartSQL},
{&s.setAvatarURLStmt, setAvatarURLSQL},
@@ -73,14 +75,14 @@ func (s *profilesStatements) prepare(db *sql.DB) (err error) {
}.Prepare(db)
}
-func (s *profilesStatements) insertProfile(
+func (s *profilesStatements) InsertProfile(
ctx context.Context, txn *sql.Tx, localpart string,
) (err error) {
_, err = sqlutil.TxStmt(txn, s.insertProfileStmt).ExecContext(ctx, localpart, "", "")
return
}
-func (s *profilesStatements) selectProfileByLocalpart(
+func (s *profilesStatements) SelectProfileByLocalpart(
ctx context.Context, localpart string,
) (*authtypes.Profile, error) {
var profile authtypes.Profile
@@ -93,21 +95,21 @@ func (s *profilesStatements) selectProfileByLocalpart(
return &profile, nil
}
-func (s *profilesStatements) setAvatarURL(
- ctx context.Context, localpart string, avatarURL string,
+func (s *profilesStatements) SetAvatarURL(
+ ctx context.Context, txn *sql.Tx, localpart string, avatarURL string,
) (err error) {
_, err = s.setAvatarURLStmt.ExecContext(ctx, avatarURL, localpart)
return
}
-func (s *profilesStatements) setDisplayName(
- ctx context.Context, localpart string, displayName string,
+func (s *profilesStatements) SetDisplayName(
+ ctx context.Context, txn *sql.Tx, localpart string, displayName string,
) (err error) {
_, err = s.setDisplayNameStmt.ExecContext(ctx, displayName, localpart)
return
}
-func (s *profilesStatements) selectProfilesBySearch(
+func (s *profilesStatements) SelectProfilesBySearch(
ctx context.Context, searchString string, limit int,
) ([]authtypes.Profile, error) {
var profiles []authtypes.Profile