mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-27 00:31:55 -06:00
ca5bbffd8d
* Add a new component: currentstateserver - Add a skeleton for it, with databases and a single query method. - Add integration tests for it. - Add listen/address fields in the config (breaking as this will force people to specify this to validate) Not currently hooked up to anything yet. * Unbreak config tests * Add current_state to sample config * comments
36 lines
859 B
Go
36 lines
859 B
Go
package postgres
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/matrix-org/dendrite/currentstateserver/storage/shared"
|
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
|
)
|
|
|
|
type Database struct {
|
|
shared.Database
|
|
db *sql.DB
|
|
sqlutil.PartitionOffsetStatements
|
|
}
|
|
|
|
// NewDatabase creates a new sync server database
|
|
func NewDatabase(dbDataSourceName string, dbProperties sqlutil.DbProperties) (*Database, error) {
|
|
var d Database
|
|
var err error
|
|
if d.db, err = sqlutil.Open("postgres", dbDataSourceName, dbProperties); err != nil {
|
|
return nil, err
|
|
}
|
|
if err = d.PartitionOffsetStatements.Prepare(d.db, "currentstate"); err != nil {
|
|
return nil, err
|
|
}
|
|
currRoomState, err := NewPostgresCurrentRoomStateTable(d.db)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
d.Database = shared.Database{
|
|
DB: d.db,
|
|
CurrentRoomState: currRoomState,
|
|
}
|
|
return &d, nil
|
|
}
|