func SetServiceDB(db Storer)
SetServiceDB sets the global service DB instance.
type NopStorage struct{}
NopStorage nops every store API call. This is intended to be embedded into derived structs in tests
func (s *NopStorage) DeleteService(serviceID string) (err error)
DeleteService NOP
func (s *NopStorage) InsertFromConfig(cfg *api.ConfigFile) error
InsertFromConfig NOP
func (s *NopStorage) LoadAuthRealm(realmID string) (realm types.AuthRealm, err error)
LoadAuthRealm NOP
func (s *NopStorage) LoadAuthRealmsByType(realmType string) (realms []types.AuthRealm, err error)
LoadAuthRealmsByType NOP
func (s *NopStorage) LoadAuthSessionByID(realmID, sessionID string) (session types.AuthSession, err error)
LoadAuthSessionByID NOP
func (s *NopStorage) LoadAuthSessionByUser(realmID, userID string) (session types.AuthSession, err error)
LoadAuthSessionByUser NOP
func (s *NopStorage) LoadBotOptions(userID, roomID string) (opts types.BotOptions, err error)
LoadBotOptions NOP
func (s *NopStorage) LoadMatrixClientConfig(userID string) (config api.ClientConfig, err error)
LoadMatrixClientConfig NOP
func (s *NopStorage) LoadMatrixClientConfigs() (configs []api.ClientConfig, err error)
LoadMatrixClientConfigs NOP
func (s *NopStorage) LoadNextBatch(userID string) (nextBatch string, err error)
LoadNextBatch NOP
func (s *NopStorage) LoadService(serviceID string) (service types.Service, err error)
LoadService NOP
func (s *NopStorage) LoadServicesByType(serviceType string) (services []types.Service, err error)
LoadServicesByType NOP
func (s *NopStorage) LoadServicesForUser(serviceUserID string) (services []types.Service, err error)
LoadServicesForUser NOP
func (s *NopStorage) RemoveAuthSession(realmID, userID string) error
RemoveAuthSession NOP
func (s *NopStorage) StoreAuthRealm(realm types.AuthRealm) (old types.AuthRealm, err error)
StoreAuthRealm NOP
func (s *NopStorage) StoreAuthSession(session types.AuthSession) (old types.AuthSession, err error)
StoreAuthSession NOP
func (s *NopStorage) StoreBotOptions(opts types.BotOptions) (oldOpts types.BotOptions, err error)
StoreBotOptions NOP
func (s *NopStorage) StoreMatrixClientConfig(config api.ClientConfig) (oldConfig api.ClientConfig, err error)
StoreMatrixClientConfig NOP
func (s *NopStorage) StoreService(service types.Service) (oldService types.Service, err error)
StoreService NOP
func (s *NopStorage) UpdateNextBatch(userID, nextBatch string) (err error)
UpdateNextBatch NOP
type ServiceDB struct {
// contains filtered or unexported fields
}
A ServiceDB stores the configuration for the services
func Open(databaseType, databaseURL string) (serviceDB *ServiceDB, err error)
Open a SQL database to use as a ServiceDB. This will automatically create the necessary database tables if they aren't already present.
func (d *ServiceDB) DeleteService(serviceID string) (err error)
DeleteService deletes the given service from the database.
func (d *ServiceDB) InsertFromConfig(cfg *api.ConfigFile) error
InsertFromConfig inserts entries from the config file into the database. This only really makes sense for in-memory databases.
func (d *ServiceDB) LoadAuthRealm(realmID string) (realm types.AuthRealm, err error)
LoadAuthRealm loads an AuthRealm from the database. Returns sql.ErrNoRows if the realm isn't in the database.
func (d *ServiceDB) LoadAuthRealmsByType(realmType string) (realms []types.AuthRealm, err error)
LoadAuthRealmsByType loads all auth realms with the given type from the database. The realms are ordered based on their realm ID. Returns an empty list if there are no realms with that type.
func (d *ServiceDB) LoadAuthSessionByID(realmID, sessionID string) (session types.AuthSession, err error)
LoadAuthSessionByID loads an AuthSession from the database based on the given realm and session ID. Returns sql.ErrNoRows if the session isn't in the database.
func (d *ServiceDB) LoadAuthSessionByUser(realmID, userID string) (session types.AuthSession, err error)
LoadAuthSessionByUser loads an AuthSession from the database based on the given realm and user ID. Returns sql.ErrNoRows if the session isn't in the database.
func (d *ServiceDB) LoadBotOptions(userID, roomID string) (opts types.BotOptions, err error)
LoadBotOptions loads bot options from the database. Returns sql.ErrNoRows if the bot options isn't in the database.
func (d *ServiceDB) LoadMatrixClientConfig(userID string) (config api.ClientConfig, err error)
LoadMatrixClientConfig loads a Matrix client config from the database. Returns sql.ErrNoRows if the client isn't in the database.
func (d *ServiceDB) LoadMatrixClientConfigs() (configs []api.ClientConfig, err error)
LoadMatrixClientConfigs loads all Matrix client configs from the database.
func (d *ServiceDB) LoadNextBatch(userID string) (nextBatch string, err error)
LoadNextBatch loads the next_batch token for the given user.
func (d *ServiceDB) LoadService(serviceID string) (service types.Service, err error)
LoadService loads a service from the database. Returns sql.ErrNoRows if the service isn't in the database.
func (d *ServiceDB) LoadServicesByType(serviceType string) (services []types.Service, err error)
LoadServicesByType loads all the bot services configured for a given type. Returns an empty list if there aren't any services configured.
func (d *ServiceDB) LoadServicesForUser(serviceUserID string) (services []types.Service, err error)
LoadServicesForUser loads all the bot services configured for a given user. Returns an empty list if there aren't any services configured.
func (d *ServiceDB) RemoveAuthSession(realmID, userID string) error
RemoveAuthSession removes the auth session for the given user on the given realm. No error is returned if the session did not exist in the first place.
func (d *ServiceDB) StoreAuthRealm(realm types.AuthRealm) (old types.AuthRealm, err error)
StoreAuthRealm stores the given AuthRealm, clobbering based on the realm ID. This function updates the time added/updated values. The previous realm, if any, is returned.
func (d *ServiceDB) StoreAuthSession(session types.AuthSession) (old types.AuthSession, err error)
StoreAuthSession stores the given AuthSession, clobbering based on the tuple of user ID and realm ID. This function updates the time added/updated values. The previous session, if any, is returned.
func (d *ServiceDB) StoreBotOptions(opts types.BotOptions) (oldOpts types.BotOptions, err error)
StoreBotOptions stores a BotOptions into the database either by inserting a new bot options or updating an existing bot options. Returns the old bot options if there was one.
func (d *ServiceDB) StoreMatrixClientConfig(config api.ClientConfig) (oldConfig api.ClientConfig, err error)
StoreMatrixClientConfig stores the Matrix client config for a bot service. If a config already exists then it will be updated, otherwise a new config will be inserted. The previous config is returned.
func (d *ServiceDB) StoreService(service types.Service) (oldService types.Service, err error)
StoreService stores a service into the database either by inserting a new service or updating an existing service. Returns the old service if there was one.
func (d *ServiceDB) UpdateNextBatch(userID, nextBatch string) (err error)
UpdateNextBatch updates the next_batch token for the given user.
type Storer interface { StoreMatrixClientConfig(config api.ClientConfig) (oldConfig api.ClientConfig, err error) LoadMatrixClientConfigs() (configs []api.ClientConfig, err error) LoadMatrixClientConfig(userID string) (config api.ClientConfig, err error) UpdateNextBatch(userID, nextBatch string) (err error) LoadNextBatch(userID string) (nextBatch string, err error) LoadService(serviceID string) (service types.Service, err error) DeleteService(serviceID string) (err error) LoadServicesForUser(serviceUserID string) (services []types.Service, err error) LoadServicesByType(serviceType string) (services []types.Service, err error) StoreService(service types.Service) (oldService types.Service, err error) LoadAuthRealm(realmID string) (realm types.AuthRealm, err error) LoadAuthRealmsByType(realmType string) (realms []types.AuthRealm, err error) StoreAuthRealm(realm types.AuthRealm) (old types.AuthRealm, err error) StoreAuthSession(session types.AuthSession) (old types.AuthSession, err error) LoadAuthSessionByUser(realmID, userID string) (session types.AuthSession, err error) LoadAuthSessionByID(realmID, sessionID string) (session types.AuthSession, err error) RemoveAuthSession(realmID, userID string) error LoadBotOptions(userID, roomID string) (opts types.BotOptions, err error) StoreBotOptions(opts types.BotOptions) (oldOpts types.BotOptions, err error) InsertFromConfig(cfg *api.ConfigFile) error }
Storer is the interface which needs to be conformed to in order to persist Go-NEB data
func GetServiceDB() Storer
GetServiceDB gets the global service DB instance.