mongo

package
v0.0.0-...-317f81d Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DbVersion = "1.1.0"

	DbName        = "inventory"
	DbDevicesColl = "devices"

	DbDevId              = "_id"
	DbDevAttributes      = "attributes"
	DbDevGroup           = "group"
	DbDevRevision        = "revision"
	DbDevUpdatedTs       = "updated_ts"
	DbDevAttributesText  = "text"
	DbDevAttributesTs    = "timestamp"
	DbDevAttributesDesc  = "description"
	DbDevAttributesValue = "value"
	DbDevAttributesScope = "scope"
	DbDevAttributesName  = "name"
	DbDevAttributesGroup = DbDevAttributes + "." +
		model.AttrScopeSystem + "-" + model.AttrNameGroup
	DbDevAttributesGroupValue = DbDevAttributesGroup + "." +
		DbDevAttributesValue

	DbScopeInventory = "inventory"

	FiltersAttributesMaxDevices = 5000
	FiltersAttributesLimit      = 500
)

Variables

View Source
var (
	ErrNotFound = errors.New("mongo: no documents in result")
)

Functions

func NewDataStoreMongo

func NewDataStoreMongo(config DataStoreMongoConfig) (store.DataStore, error)

config.ConnectionString must contain a valid

func NewDataStoreMongoWithSession

func NewDataStoreMongoWithSession(client *mongo.Client) store.DataStore

Types

type DataStoreMongo

type DataStoreMongo struct {
	// contains filtered or unexported fields
}

func (*DataStoreMongo) AddDevice

func (db *DataStoreMongo) AddDevice(ctx context.Context, dev *model.Device) error

AddDevice inserts a new device, initializing the inventory data.

func (*DataStoreMongo) DeleteDevices

func (db *DataStoreMongo) DeleteDevices(
	ctx context.Context, ids []model.DeviceID,
) (*model.UpdateResult, error)

func (*DataStoreMongo) DeleteGroup

func (db *DataStoreMongo) DeleteGroup(
	ctx context.Context,
	group model.GroupName,
) (chan model.DeviceID, error)

func (*DataStoreMongo) GetAllAttributeNames

func (db *DataStoreMongo) GetAllAttributeNames(ctx context.Context) ([]string, error)

func (*DataStoreMongo) GetDevice

func (db *DataStoreMongo) GetDevice(
	ctx context.Context,
	id model.DeviceID,
) (*model.Device, error)

func (*DataStoreMongo) GetDeviceGroup

func (db *DataStoreMongo) GetDeviceGroup(
	ctx context.Context,
	id model.DeviceID,
) (model.GroupName, error)

func (*DataStoreMongo) GetDevices

func (db *DataStoreMongo) GetDevices(
	ctx context.Context,
	q store.ListQuery,
) ([]model.Device, int, error)

func (*DataStoreMongo) GetDevicesByGroup

func (db *DataStoreMongo) GetDevicesByGroup(
	ctx context.Context,
	group model.GroupName,
	skip,
	limit int,
) ([]model.DeviceID, int, error)

func (*DataStoreMongo) GetFiltersAttributes

func (db *DataStoreMongo) GetFiltersAttributes(
	ctx context.Context,
) ([]model.FilterAttribute, error)

func (*DataStoreMongo) ListGroups

func (db *DataStoreMongo) ListGroups(
	ctx context.Context,
	filters []model.FilterPredicate,
) ([]model.GroupName, error)

func (*DataStoreMongo) Maintenance

func (db *DataStoreMongo) Maintenance(
	ctx context.Context,
	version string,
	tenantIDs ...string,
) error

func (*DataStoreMongo) Migrate

func (db *DataStoreMongo) Migrate(ctx context.Context, version string) error

func (*DataStoreMongo) MigrateTenant

func (db *DataStoreMongo) MigrateTenant(
	ctx context.Context,
	version string,
	tenantId string,
) error

func (*DataStoreMongo) Ping

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

func (*DataStoreMongo) SearchDevices

func (db *DataStoreMongo) SearchDevices(
	ctx context.Context,
	searchParams model.SearchParams,
) ([]model.Device, int, error)

func (*DataStoreMongo) UnsetDevicesGroup

func (db *DataStoreMongo) UnsetDevicesGroup(
	ctx context.Context,
	deviceIDs []model.DeviceID,
	group model.GroupName,
) (*model.UpdateResult, error)

func (*DataStoreMongo) UpdateDeviceText

func (db *DataStoreMongo) UpdateDeviceText(
	ctx context.Context,
	deviceID model.DeviceID,
	text string,
) error

UpdateDeviceText updates the device text field

func (*DataStoreMongo) UpdateDevicesGroup

func (db *DataStoreMongo) UpdateDevicesGroup(
	ctx context.Context,
	devIDs []model.DeviceID,
	group model.GroupName,
) (*model.UpdateResult, error)

func (*DataStoreMongo) UpsertDevicesAttributes

func (db *DataStoreMongo) UpsertDevicesAttributes(
	ctx context.Context,
	ids []model.DeviceID,
	attrs model.DeviceAttributes,
) (*model.UpdateResult, error)

func (*DataStoreMongo) UpsertDevicesAttributesWithRevision

func (db *DataStoreMongo) UpsertDevicesAttributesWithRevision(
	ctx context.Context,
	devices []model.DeviceUpdate,
	attrs model.DeviceAttributes,
) (*model.UpdateResult, error)

func (*DataStoreMongo) UpsertDevicesAttributesWithUpdated

func (db *DataStoreMongo) UpsertDevicesAttributesWithUpdated(
	ctx context.Context,
	ids []model.DeviceID,
	attrs model.DeviceAttributes,
	scope string,
	etag string,
) (*model.UpdateResult, error)

func (*DataStoreMongo) UpsertRemoveDeviceAttributes

func (db *DataStoreMongo) UpsertRemoveDeviceAttributes(
	ctx context.Context,
	id model.DeviceID,
	updateAttrs model.DeviceAttributes,
	removeAttrs model.DeviceAttributes,
	scope string,
	etag string,
) (*model.UpdateResult, error)

func (*DataStoreMongo) WithAutomigrate

func (db *DataStoreMongo) WithAutomigrate() store.DataStore

WithAutomigrate enables automatic migration and returns a new datastore based on current one

type DataStoreMongoConfig

type DataStoreMongoConfig struct {
	// connection string
	ConnectionString string

	// SSL support
	SSL           bool
	SSLSkipVerify bool

	// Overwrites credentials provided in connection string if provided
	Username string
	Password string
}

Jump to

Keyboard shortcuts

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