2020-06-30 11:37:21 +02:00
|
|
|
package sqlite3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/currentstateserver/storage/shared"
|
2020-08-10 15:18:04 +02:00
|
|
|
"github.com/matrix-org/dendrite/internal/config"
|
2020-06-30 11:37:21 +02:00
|
|
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Database struct {
|
|
|
|
shared.Database
|
|
|
|
db *sql.DB
|
|
|
|
sqlutil.PartitionOffsetStatements
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewDatabase creates a new sync server database
|
|
|
|
// nolint: gocyclo
|
2020-08-10 15:18:04 +02:00
|
|
|
func NewDatabase(dbProperties *config.DatabaseOptions) (*Database, error) {
|
2020-06-30 11:37:21 +02:00
|
|
|
var d Database
|
2020-08-10 15:18:04 +02:00
|
|
|
var err error
|
|
|
|
if d.db, err = sqlutil.Open(dbProperties); err != nil {
|
2020-06-30 11:37:21 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err = d.PartitionOffsetStatements.Prepare(d.db, "currentstate"); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
currRoomState, err := NewSqliteCurrentRoomStateTable(d.db)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
d.Database = shared.Database{
|
|
|
|
DB: d.db,
|
|
|
|
CurrentRoomState: currRoomState,
|
|
|
|
}
|
|
|
|
return &d, nil
|
|
|
|
}
|