mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 14:12:47 +00:00
Refactor user API storage (#2202)
* Refactor User API database * Fix migration bugs
This commit is contained in:
parent
9bd5e414c9
commit
9f4a39e8e0
22 changed files with 1165 additions and 1671 deletions
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/userapi/storage/tables"
|
||||
)
|
||||
|
||||
const accountDataSchema = `
|
||||
|
@ -56,19 +57,20 @@ type accountDataStatements struct {
|
|||
selectAccountDataByTypeStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (s *accountDataStatements) prepare(db *sql.DB) (err error) {
|
||||
_, err = db.Exec(accountDataSchema)
|
||||
func NewPostgresAccountDataTable(db *sql.DB) (tables.AccountDataTable, error) {
|
||||
s := &accountDataStatements{}
|
||||
_, err := db.Exec(accountDataSchema)
|
||||
if err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
return sqlutil.StatementList{
|
||||
return s, sqlutil.StatementList{
|
||||
{&s.insertAccountDataStmt, insertAccountDataSQL},
|
||||
{&s.selectAccountDataStmt, selectAccountDataSQL},
|
||||
{&s.selectAccountDataByTypeStmt, selectAccountDataByTypeSQL},
|
||||
}.Prepare(db)
|
||||
}
|
||||
|
||||
func (s *accountDataStatements) insertAccountData(
|
||||
func (s *accountDataStatements) InsertAccountData(
|
||||
ctx context.Context, txn *sql.Tx, localpart, roomID, dataType string, content json.RawMessage,
|
||||
) (err error) {
|
||||
stmt := sqlutil.TxStmt(txn, s.insertAccountDataStmt)
|
||||
|
@ -76,7 +78,7 @@ func (s *accountDataStatements) insertAccountData(
|
|||
return
|
||||
}
|
||||
|
||||
func (s *accountDataStatements) selectAccountData(
|
||||
func (s *accountDataStatements) SelectAccountData(
|
||||
ctx context.Context, localpart string,
|
||||
) (
|
||||
/* global */ map[string]json.RawMessage,
|
||||
|
@ -114,7 +116,7 @@ func (s *accountDataStatements) selectAccountData(
|
|||
return global, rooms, rows.Err()
|
||||
}
|
||||
|
||||
func (s *accountDataStatements) selectAccountDataByType(
|
||||
func (s *accountDataStatements) SelectAccountDataByType(
|
||||
ctx context.Context, localpart, roomID, dataType string,
|
||||
) (data json.RawMessage, err error) {
|
||||
var bytes []byte
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue