mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 06:12:45 +00:00
Convert transactions/rooms table to share more code (#1063)
* Convert rooms table * Convert transactions table * Convert rooms table and factor out lots of functions * I think you'll be needing this..
This commit is contained in:
parent
803af87dc4
commit
19aa44ecae
12 changed files with 409 additions and 600 deletions
|
@ -18,6 +18,8 @@ package postgres
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
)
|
||||
|
||||
const transactionsSchema = `
|
||||
|
@ -51,20 +53,21 @@ type transactionStatements struct {
|
|||
selectTransactionEventIDStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (s *transactionStatements) prepare(db *sql.DB) (err error) {
|
||||
_, err = db.Exec(transactionsSchema)
|
||||
func NewPostgresTransactionsTable(db *sql.DB) (tables.Transactions, error) {
|
||||
s := &transactionStatements{}
|
||||
_, err := db.Exec(transactionsSchema)
|
||||
if err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return statementList{
|
||||
return s, statementList{
|
||||
{&s.insertTransactionStmt, insertTransactionSQL},
|
||||
{&s.selectTransactionEventIDStmt, selectTransactionEventIDSQL},
|
||||
}.prepare(db)
|
||||
}
|
||||
|
||||
func (s *transactionStatements) insertTransaction(
|
||||
ctx context.Context,
|
||||
func (s *transactionStatements) InsertTransaction(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
transactionID string,
|
||||
sessionID int64,
|
||||
userID string,
|
||||
|
@ -76,7 +79,7 @@ func (s *transactionStatements) insertTransaction(
|
|||
return
|
||||
}
|
||||
|
||||
func (s *transactionStatements) selectTransactionEventID(
|
||||
func (s *transactionStatements) SelectTransactionEventID(
|
||||
ctx context.Context,
|
||||
transactionID string,
|
||||
sessionID int64,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue