aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage/postgres/account_data_table.go
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-05-14 09:53:55 +0100
committerGitHub <noreply@github.com>2020-05-14 09:53:55 +0100
commit9ed68a3125d9024f52bf89810abf3b203f4b25b7 (patch)
treef30a532965d841de3d8faa370d3bf5cc8beb5ba1 /syncapi/storage/postgres/account_data_table.go
parenta25d477cdb8f1ba49b3b5e9d931f808ae45b4853 (diff)
Factor out account data and events table (#1031)
* Factor out account data * Factor out events table and EDU cache * linting * fix npe
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