mirror of
https://github.com/1f349/dendrite.git
synced 2024-12-24 09:14:11 +00:00
9d53351dc2
* Offset updates take place using TransactionWriter * Refactor TransactionWriter in current state server * Refactor TransactionWriter in federation sender * Refactor TransactionWriter in key server * Refactor TransactionWriter in media API * Refactor TransactionWriter in server key API * Refactor TransactionWriter in sync API * Refactor TransactionWriter in user API * Fix deadlocking Sync API tests * Un-deadlock device database * Fix appservice API * Rename TransactionWriters to Writers * Move writers up a layer in sync API * Document sqlutil.Writer interface * Add note to Writer documentation
40 lines
961 B
Go
40 lines
961 B
Go
package postgres
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/matrix-org/dendrite/currentstateserver/storage/shared"
|
|
"github.com/matrix-org/dendrite/internal/config"
|
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
|
)
|
|
|
|
type Database struct {
|
|
shared.Database
|
|
db *sql.DB
|
|
writer sqlutil.Writer
|
|
sqlutil.PartitionOffsetStatements
|
|
}
|
|
|
|
// NewDatabase creates a new sync server database
|
|
func NewDatabase(dbProperties *config.DatabaseOptions) (*Database, error) {
|
|
var d Database
|
|
var err error
|
|
if d.db, err = sqlutil.Open(dbProperties); err != nil {
|
|
return nil, err
|
|
}
|
|
d.writer = sqlutil.NewDummyWriter()
|
|
if err = d.PartitionOffsetStatements.Prepare(d.db, d.writer, "currentstate"); err != nil {
|
|
return nil, err
|
|
}
|
|
currRoomState, err := NewPostgresCurrentRoomStateTable(d.db)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
d.Database = shared.Database{
|
|
DB: d.db,
|
|
Writer: d.writer,
|
|
CurrentRoomState: currRoomState,
|
|
}
|
|
return &d, nil
|
|
}
|