mongo

package
v0.0.0-...-f5ffca4 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: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CollDevices refers to the collection name for device configurations
	CollDevices = "devices"

	KeyTenantID = "tenant_id"
)
View Source
const (
	// DbVersion is the current schema version
	DbVersion = "1.0.1"

	// DbName is the database name
	DbName = "deviceconfig"
)
View Source
const (
	ErrCodeDuplicateKey = 11000
)

Variables

This section is empty.

Functions

func IsDuplicateKeyErr

func IsDuplicateKeyErr(err error) bool

IsDuplicateKeyErr checks the errors and inspects if (one of) the error(s) is duplicate key a error.

Types

type MongoStore

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

MongoStore is the data storage service

func NewMongoStore

func NewMongoStore(ctx context.Context, config MongoStoreConfig) (*MongoStore, error)

SetupDataStore returns the mongo data store and optionally runs migrations

func (*MongoStore) Close

func (db *MongoStore) Close(ctx context.Context) error

Close disconnects the client

func (*MongoStore) Database

func (db *MongoStore) Database(ctx context.Context, opt ...*mopts.DatabaseOptions) *mongo.Database

func (*MongoStore) DeleteDevice

func (db *MongoStore) DeleteDevice(ctx context.Context, devID string) error

func (*MongoStore) DropDatabase

func (db *MongoStore) DropDatabase(ctx context.Context) error

func (*MongoStore) GetDevice

func (db *MongoStore) GetDevice(ctx context.Context, devID string) (model.Device, error)

func (*MongoStore) InsertDevice

func (db *MongoStore) InsertDevice(ctx context.Context, dev model.Device) error

func (*MongoStore) Migrate

func (db *MongoStore) Migrate(ctx context.Context, version string, automigrate bool) error

Migrate applies all migrations under the given context. That is, if ctx has an associated identity.Identity set, it will ONLY migrate the single tenant's db. If ctx does not have an identity, all deviceconfig databases will be migrated to the given version.

func (*MongoStore) MigrateLatest

func (db *MongoStore) MigrateLatest(ctx context.Context) error

func (*MongoStore) Ping

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

Ping verifies the connection to the database

func (*MongoStore) ReplaceConfiguration

func (db *MongoStore) ReplaceConfiguration(ctx context.Context, dev model.Device) error

func (*MongoStore) ReplaceReportedConfiguration

func (db *MongoStore) ReplaceReportedConfiguration(ctx context.Context, dev model.Device) error

func (*MongoStore) SetDeploymentID

func (db *MongoStore) SetDeploymentID(ctx context.Context, devID string,
	deploymentID uuid.UUID) error

func (*MongoStore) UpdateConfiguration

func (db *MongoStore) UpdateConfiguration(
	ctx context.Context,
	devID string,
	attrs model.Attributes,
) error

type MongoStoreConfig

type MongoStoreConfig struct {
	// MongoURL holds the URL to the MongoDB server.
	MongoURL *url.URL
	// TLSConfig holds optional tls configuration options for connecting
	// to the MongoDB server.
	TLSConfig *tls.Config
	// Username holds the user id credential for authenticating with the
	// MongoDB server.
	Username string
	// Password holds the password credential for authenticating with the
	// MongoDB server.
	Password string

	// DbName contains the name of the deviceconfig database.
	DbName string
}

Jump to

Keyboard shortcuts

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