mongo

package
v0.0.0-...-91e9984 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

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 NewClient

func NewClient(ctx context.Context, c config.Reader) (*mongo.Client, error)

NewClient returns a mongo client

func SetEventExpiration

func SetEventExpiration(exp int64)

func SetupDataStore

func SetupDataStore(conf *Config) (store.DataStore, error)

SetupDataStore returns the mongo data store and optionally runs migrations

Types

type Config

type Config struct {
	Automigrate *bool
	DbName      *string
}

func NewConfig

func NewConfig() *Config

func (*Config) SetAutomigrate

func (c *Config) SetAutomigrate(migrate bool) *Config

func (*Config) SetDbName

func (c *Config) SetDbName(name string) *Config

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) 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 (db *DataStoreMongo) GetAllDevices(ctx context.Context) (store.Iterator, error)

func (*DataStoreMongo) GetDevice

func (db *DataStoreMongo) GetDevice(
	ctx context.Context,
	deviceID string,
) (*model.Device, error)

func (*DataStoreMongo) GetDeviceByIntegrationID

func (db *DataStoreMongo) GetDeviceByIntegrationID(
	ctx context.Context,
	deviceID string,
	integrationID uuid.UUID,
) (*model.Device, error)

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) Migrate

func (ds *DataStoreMongo) Migrate(ctx context.Context) error

func (*DataStoreMongo) Ping

func (db *DataStoreMongo) Ping(ctx context.Context) error

Ping verifies the connection to the database

func (*DataStoreMongo) RemoveDevicesFromIntegration

func (db *DataStoreMongo) RemoveDevicesFromIntegration(
	ctx context.Context,
	integrationID uuid.UUID,
) (int64, error)

func (*DataStoreMongo) RemoveIntegration

func (db *DataStoreMongo) RemoveIntegration(ctx context.Context, integrationId uuid.UUID) error

func (*DataStoreMongo) SaveEvent

func (db *DataStoreMongo) SaveEvent(
	ctx context.Context,
	event model.Event,
) error

func (*DataStoreMongo) SetIntegrationCredentials

func (db *DataStoreMongo) SetIntegrationCredentials(
	ctx context.Context,
	integrationId uuid.UUID,
	credentials model.Credentials,
) error

func (*DataStoreMongo) UpsertDeviceIntegrations

func (db *DataStoreMongo) UpsertDeviceIntegrations(
	ctx context.Context,
	deviceID string,
	integrationIDs []uuid.UUID,
) (*model.Device, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL