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
|
@ -20,6 +20,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/userapi/storage/tables"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||
)
|
||||
|
@ -60,13 +61,15 @@ type threepidStatements struct {
|
|||
deleteThreePIDStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (s *threepidStatements) prepare(db *sql.DB) (err error) {
|
||||
s.db = db
|
||||
_, err = db.Exec(threepidSchema)
|
||||
if err != nil {
|
||||
return
|
||||
func NewSQLiteThreePIDTable(db *sql.DB) (tables.ThreePIDTable, error) {
|
||||
s := &threepidStatements{
|
||||
db: db,
|
||||
}
|
||||
return sqlutil.StatementList{
|
||||
_, err := db.Exec(threepidSchema)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s, sqlutil.StatementList{
|
||||
{&s.selectLocalpartForThreePIDStmt, selectLocalpartForThreePIDSQL},
|
||||
{&s.selectThreePIDsForLocalpartStmt, selectThreePIDsForLocalpartSQL},
|
||||
{&s.insertThreePIDStmt, insertThreePIDSQL},
|
||||
|
@ -74,7 +77,7 @@ func (s *threepidStatements) prepare(db *sql.DB) (err error) {
|
|||
}.Prepare(db)
|
||||
}
|
||||
|
||||
func (s *threepidStatements) selectLocalpartForThreePID(
|
||||
func (s *threepidStatements) SelectLocalpartForThreePID(
|
||||
ctx context.Context, txn *sql.Tx, threepid string, medium string,
|
||||
) (localpart string, err error) {
|
||||
stmt := sqlutil.TxStmt(txn, s.selectLocalpartForThreePIDStmt)
|
||||
|
@ -85,7 +88,7 @@ func (s *threepidStatements) selectLocalpartForThreePID(
|
|||
return
|
||||
}
|
||||
|
||||
func (s *threepidStatements) selectThreePIDsForLocalpart(
|
||||
func (s *threepidStatements) SelectThreePIDsForLocalpart(
|
||||
ctx context.Context, localpart string,
|
||||
) (threepids []authtypes.ThreePID, err error) {
|
||||
rows, err := s.selectThreePIDsForLocalpartStmt.QueryContext(ctx, localpart)
|
||||
|
@ -109,7 +112,7 @@ func (s *threepidStatements) selectThreePIDsForLocalpart(
|
|||
return threepids, rows.Err()
|
||||
}
|
||||
|
||||
func (s *threepidStatements) insertThreePID(
|
||||
func (s *threepidStatements) InsertThreePID(
|
||||
ctx context.Context, txn *sql.Tx, threepid, medium, localpart string,
|
||||
) (err error) {
|
||||
stmt := sqlutil.TxStmt(txn, s.insertThreePIDStmt)
|
||||
|
@ -117,7 +120,7 @@ func (s *threepidStatements) insertThreePID(
|
|||
return err
|
||||
}
|
||||
|
||||
func (s *threepidStatements) deleteThreePID(
|
||||
func (s *threepidStatements) DeleteThreePID(
|
||||
ctx context.Context, txn *sql.Tx, threepid string, medium string) (err error) {
|
||||
stmt := sqlutil.TxStmt(txn, s.deleteThreePIDStmt)
|
||||
_, err = stmt.ExecContext(ctx, threepid, medium)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue