aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage/postgres/account_data_table.go
diff options
context:
space:
mode:
Diffstat (limited to 'syncapi/storage/postgres/account_data_table.go')
-rw-r--r--syncapi/storage/postgres/account_data_table.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/syncapi/storage/postgres/account_data_table.go b/syncapi/storage/postgres/account_data_table.go
index d1e3b527..58fb2198 100644
--- a/syncapi/storage/postgres/account_data_table.go
+++ b/syncapi/storage/postgres/account_data_table.go
@@ -21,6 +21,7 @@ import (
"github.com/lib/pq"
"github.com/matrix-org/dendrite/common"
+ "github.com/matrix-org/dendrite/syncapi/storage/tables"
"github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib"
)
@@ -70,32 +71,33 @@ type accountDataStatements struct {
selectMaxAccountDataIDStmt *sql.Stmt
}
-func (s *accountDataStatements) prepare(db *sql.DB) (err error) {
- _, err = db.Exec(accountDataSchema)
+func NewPostgresAccountDataTable(db *sql.DB) (tables.AccountData, error) {
+ s := &accountDataStatements{}
+ _, err := db.Exec(accountDataSchema)
if err != nil {
- return
+ return nil, err
}
if s.insertAccountDataStmt, err = db.Prepare(insertAccountDataSQL); err != nil {
- return
+ return nil, err
}
if s.selectAccountDataInRangeStmt, err = db.Prepare(selectAccountDataInRangeSQL); err != nil {
- return
+ return nil, err
}
if s.selectMaxAccountDataIDStmt, err = db.Prepare(selectMaxAccountDataIDSQL); err != nil {
- return
+ return nil, err
}
- return
+ return s, nil
}
-func (s *accountDataStatements) insertAccountData(
- ctx context.Context,
+func (s *accountDataStatements) InsertAccountData(
+ ctx context.Context, txn *sql.Tx,
userID, roomID, dataType string,
) (pos types.StreamPosition, err error) {
err = s.insertAccountDataStmt.QueryRowContext(ctx, userID, roomID, dataType).Scan(&pos)
return
}
-func (s *accountDataStatements) selectAccountDataInRange(
+func (s *accountDataStatements) SelectAccountDataInRange(
ctx context.Context,
userID string,
oldPos, newPos types.StreamPosition,
@@ -137,7 +139,7 @@ func (s *accountDataStatements) selectAccountDataInRange(
return data, rows.Err()
}
-func (s *accountDataStatements) selectMaxAccountDataID(
+func (s *accountDataStatements) SelectMaxAccountDataID(
ctx context.Context, txn *sql.Tx,
) (id int64, err error) {
var nullableID sql.NullInt64