mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-10 06:53:00 +00:00
803af87dc4
* Convert event_json table * Convert the events table
80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
package shared
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
|
"github.com/matrix-org/dendrite/roomserver/types"
|
|
)
|
|
|
|
type Database struct {
|
|
EventsTable tables.Events
|
|
EventJSONTable tables.EventJSON
|
|
EventTypesTable tables.EventTypes
|
|
EventStateKeysTable tables.EventStateKeys
|
|
}
|
|
|
|
// EventTypeNIDs implements state.RoomStateDatabase
|
|
func (d *Database) EventTypeNIDs(
|
|
ctx context.Context, eventTypes []string,
|
|
) (map[string]types.EventTypeNID, error) {
|
|
return d.EventTypesTable.BulkSelectEventTypeNID(ctx, eventTypes)
|
|
}
|
|
|
|
// EventStateKeys implements query.RoomserverQueryAPIDatabase
|
|
func (d *Database) EventStateKeys(
|
|
ctx context.Context, eventStateKeyNIDs []types.EventStateKeyNID,
|
|
) (map[types.EventStateKeyNID]string, error) {
|
|
return d.EventStateKeysTable.BulkSelectEventStateKey(ctx, eventStateKeyNIDs)
|
|
}
|
|
|
|
// EventStateKeyNIDs implements state.RoomStateDatabase
|
|
func (d *Database) EventStateKeyNIDs(
|
|
ctx context.Context, eventStateKeys []string,
|
|
) (map[string]types.EventStateKeyNID, error) {
|
|
return d.EventStateKeysTable.BulkSelectEventStateKeyNID(ctx, eventStateKeys)
|
|
}
|
|
|
|
// StateEntriesForEventIDs implements input.EventDatabase
|
|
func (d *Database) StateEntriesForEventIDs(
|
|
ctx context.Context, eventIDs []string,
|
|
) ([]types.StateEntry, error) {
|
|
return d.EventsTable.BulkSelectStateEventByID(ctx, eventIDs)
|
|
}
|
|
|
|
// EventNIDs implements query.RoomserverQueryAPIDatabase
|
|
func (d *Database) EventNIDs(
|
|
ctx context.Context, eventIDs []string,
|
|
) (map[string]types.EventNID, error) {
|
|
return d.EventsTable.BulkSelectEventNID(ctx, eventIDs)
|
|
}
|
|
|
|
// SetState implements input.EventDatabase
|
|
func (d *Database) SetState(
|
|
ctx context.Context, eventNID types.EventNID, stateNID types.StateSnapshotNID,
|
|
) error {
|
|
return d.EventsTable.UpdateEventState(ctx, eventNID, stateNID)
|
|
}
|
|
|
|
// StateAtEventIDs implements input.EventDatabase
|
|
func (d *Database) StateAtEventIDs(
|
|
ctx context.Context, eventIDs []string,
|
|
) ([]types.StateAtEvent, error) {
|
|
return d.EventsTable.BulkSelectStateAtEventByID(ctx, eventIDs)
|
|
}
|
|
|
|
// SnapshotNIDFromEventID implements state.RoomStateDatabase
|
|
func (d *Database) SnapshotNIDFromEventID(
|
|
ctx context.Context, eventID string,
|
|
) (types.StateSnapshotNID, error) {
|
|
_, stateNID, err := d.EventsTable.SelectEvent(ctx, nil, eventID)
|
|
return stateNID, err
|
|
}
|
|
|
|
// EventIDs implements input.RoomEventDatabase
|
|
func (d *Database) EventIDs(
|
|
ctx context.Context, eventNIDs []types.EventNID,
|
|
) (map[types.EventNID]string, error) {
|
|
return d.EventsTable.BulkSelectEventID(ctx, eventNIDs)
|
|
}
|