Documentation
¶
Index ¶
- Constants
- Variables
- func Migrate(ctx context.Context, db string, version string, client *mongo.Client, ...) error
- func NewClient(ctx context.Context, c config.Reader) (*mongo.Client, error)
- func SetEventExpiration(exp int64)
- func SetupDataStore(conf *Config) (store.DataStore, error)
- type Config
- type DataStoreMongo
- func (db *DataStoreMongo) Close() error
- func (db *DataStoreMongo) Collection(name string, opts ...*mopts.CollectionOptions) *mongo.Collection
- func (db *DataStoreMongo) CreateIntegration(ctx context.Context, integration model.Integration) (*model.Integration, error)
- func (db *DataStoreMongo) DeleteDevice(ctx context.Context, deviceID string) error
- func (db *DataStoreMongo) DeleteTenantData(ctx context.Context) error
- func (db *DataStoreMongo) DoDevicesExistByIntegrationID(ctx context.Context, integrationID uuid.UUID) (bool, error)
- func (db *DataStoreMongo) GetAllDevices(ctx context.Context) (store.Iterator, error)
- func (db *DataStoreMongo) GetDevice(ctx context.Context, deviceID string) (*model.Device, error)
- func (db *DataStoreMongo) GetDeviceByIntegrationID(ctx context.Context, deviceID string, integrationID uuid.UUID) (*model.Device, error)
- func (db *DataStoreMongo) GetEvents(ctx context.Context, fltr model.EventsFilter) ([]model.Event, error)
- func (db *DataStoreMongo) GetIntegrationById(ctx context.Context, integrationId uuid.UUID) (*model.Integration, error)
- func (db *DataStoreMongo) GetIntegrations(ctx context.Context, fltr model.IntegrationFilter) ([]model.Integration, error)
- func (db *DataStoreMongo) ListCollectionNames(ctx context.Context) ([]string, error)
- func (ds *DataStoreMongo) Migrate(ctx context.Context) error
- func (db *DataStoreMongo) Ping(ctx context.Context) error
- func (db *DataStoreMongo) RemoveDevicesFromIntegration(ctx context.Context, integrationID uuid.UUID) (int64, error)
- func (db *DataStoreMongo) RemoveIntegration(ctx context.Context, integrationId uuid.UUID) error
- func (db *DataStoreMongo) SaveEvent(ctx context.Context, event model.Event) error
- func (db *DataStoreMongo) SetIntegrationCredentials(ctx context.Context, integrationId uuid.UUID, credentials model.Credentials) error
- func (db *DataStoreMongo) UpsertDeviceIntegrations(ctx context.Context, deviceID string, integrationIDs []uuid.UUID) (*model.Device, error)
Constants ¶
View Source
const ( CollNameDevices = "devices" CollNameIntegrations = "integrations" KeyID = "_id" KeyIntegrationIDs = "integration_ids" KeyProvider = "provider" KeyTenantID = "tenant_id" KeyCredentials = "credentials" ConnectTimeoutSeconds = 10 )
View Source
const ( CollNameLog = "log" KeyEventTs = "event_ts" KeyEventExpireTs = "expire_ts" )
View Source
const ( IndexNameIntegrationsGet = KeyTenantID + "_" + KeyProvider + "_" + KeyID IndexNameDevices = KeyTenantID + "_" + KeyIntegrationIDs + "_" + KeyID )
View Source
const ( // DbVersion is the current schema version DbVersion = "1.1.1" // DbName is the database name DbName = "iot_manager" )
View Source
const (
IndexNameEventsGet = KeyTenantID + "_" + KeyID
)
View Source
const (
IndexNameTTL = `log_TTL`
)
Variables ¶
View Source
var ( ErrFailedToGetIntegrations = errors.New("failed to get integrations") ErrFailedToGetDevice = errors.New("failed to get device") ErrFailedToGetSettings = errors.New("failed to get settings") )
View Source
var (
ErrFailedToGetEvents = errors.New("failed to get events")
)
Functions ¶
func Migrate ¶
func Migrate(ctx context.Context, db string, version string, client *mongo.Client, automigrate bool) error
Migrate applies migrations to the database
func SetEventExpiration ¶
func SetEventExpiration(exp int64)
Types ¶
type Config ¶
func (*Config) SetAutomigrate ¶
type DataStoreMongo ¶
type DataStoreMongo struct { *Config // contains filtered or unexported fields }
DataStoreMongo is the data storage service
func NewDataStoreWithClient ¶
func NewDataStoreWithClient(client *mongo.Client, conf ...*Config) *DataStoreMongo
NewDataStoreWithClient initializes a DataStore object
func (*DataStoreMongo) Close ¶
func (db *DataStoreMongo) Close() error
func (*DataStoreMongo) Collection ¶
func (db *DataStoreMongo) Collection( name string, opts ...*mopts.CollectionOptions, ) *mongo.Collection
func (*DataStoreMongo) CreateIntegration ¶
func (db *DataStoreMongo) CreateIntegration( ctx context.Context, integration model.Integration, ) (*model.Integration, error)
func (*DataStoreMongo) DeleteDevice ¶
func (db *DataStoreMongo) DeleteDevice(ctx context.Context, deviceID string) error
func (*DataStoreMongo) DeleteTenantData ¶
func (db *DataStoreMongo) DeleteTenantData( ctx context.Context, ) error
func (*DataStoreMongo) DoDevicesExistByIntegrationID ¶
func (db *DataStoreMongo) DoDevicesExistByIntegrationID( ctx context.Context, integrationID uuid.UUID, ) (bool, error)
DoDevicesExistByIntegrationID checks if there is at least one device connected with given integration ID
func (*DataStoreMongo) GetAllDevices ¶
func (*DataStoreMongo) GetDeviceByIntegrationID ¶
func (*DataStoreMongo) GetEvents ¶
func (db *DataStoreMongo) GetEvents( ctx context.Context, fltr model.EventsFilter, ) ([]model.Event, error)
func (*DataStoreMongo) GetIntegrationById ¶
func (db *DataStoreMongo) GetIntegrationById( ctx context.Context, integrationId uuid.UUID, ) (*model.Integration, error)
func (*DataStoreMongo) GetIntegrations ¶
func (db *DataStoreMongo) GetIntegrations( ctx context.Context, fltr model.IntegrationFilter, ) ([]model.Integration, error)
func (*DataStoreMongo) ListCollectionNames ¶
func (db *DataStoreMongo) ListCollectionNames( ctx context.Context, ) ([]string, error)
func (*DataStoreMongo) Ping ¶
func (db *DataStoreMongo) Ping(ctx context.Context) error
Ping verifies the connection to the database
func (*DataStoreMongo) RemoveDevicesFromIntegration ¶
func (*DataStoreMongo) RemoveIntegration ¶
func (*DataStoreMongo) SetIntegrationCredentials ¶
func (db *DataStoreMongo) SetIntegrationCredentials( ctx context.Context, integrationId uuid.UUID, credentials model.Credentials, ) error
Click to show internal directories.
Click to hide internal directories.