db

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package db implements default implementations for the database interface used by the default service. It currently supports Mysql, Postgres and Sqlite3.

Index

Constants

View Source
const (
	StatementCreateInstallationTable = `CREATE TABLE installations (
		id CHAR (36) NOT NULL,
		token TEXT NOT NULL,
		UNIQUE(id)
	)`

	StatementCreateInstanceTable = `` /* 251-byte string literal not displayed */

	StatementCreateInstaceThingMapping = `` /* 208-byte string literal not displayed */

	StatementCreateInstallConfigTable = `` /* 221-byte string literal not displayed */

	StatementCreateInstanceConfigTable = `` /* 205-byte string literal not displayed */

)

The default database layout:

Variables

View Source
var (
	DriverMysql      = DBDriverName("mysql")
	DriverPostgresql = DBDriverName("postgres")
	DriverSqlite3    = DBDriverName("sqlite3")
)

Supported database drivers:

View Source
var DefaultOptions = &DBOptions{
	Driver: DriverSqlite3,
	DSN:    "default.sqlite3",
}

MigrationQueries will be executed when the connector calls Migrate:

Functions

This section is empty.

Types

type DBClient

type DBClient struct {
	DB     *sqlx.DB
	Logger logr.Logger
}

func NewDBClient

func NewDBClient(dbOptions *DBOptions, logger logr.Logger) (*DBClient, error)

NewDBClient creates a new mysql client

func (*DBClient) AddInstallation

func (m *DBClient) AddInstallation(ctx context.Context, installationRequest connector.InstallationRequest) error

AddInstallation adds an installation request to the database. It assumes that all data is verified beforehand and therefore does not validate anything on it's own.

func (*DBClient) AddInstallationConfiguration

func (m *DBClient) AddInstallationConfiguration(ctx context.Context, installationId string, config []connector.Configuration) error

AddInstallationConfiguration adds all configuration parameters to the database.

func (*DBClient) AddInstance

func (m *DBClient) AddInstance(ctx context.Context, instantiationRequest connector.InstantiationRequest) error

AddInstance adds an instantiation to the database.

func (*DBClient) AddInstanceConfiguration

func (m *DBClient) AddInstanceConfiguration(ctx context.Context, instanceId string, config []connector.Configuration) error

AddInstanceConfiguration adds all configuration parameters to the database.

func (*DBClient) AddThingMapping

func (m *DBClient) AddThingMapping(ctx context.Context, instanceId string, thingId string, externalId string) error

AddThingMapping adds a mapping of the instance id to a thing and external id.

func (*DBClient) GetInstallations

func (m *DBClient) GetInstallations(ctx context.Context) ([]*connector.Installation, error)

GetInstallations returns a list of all existing installations together with their provided configuration parameters.

func (*DBClient) GetInstance

func (m *DBClient) GetInstance(ctx context.Context, instanceId string) (*connector.Instance, error)

GetInstance returns the instance with the given id.

func (*DBClient) GetInstanceByThingId

func (m *DBClient) GetInstanceByThingId(ctx context.Context, thingId string) (*connector.Instance, error)

GetInstanceByThingId returns the instance with the given thing id.

func (*DBClient) GetInstanceConfiguration

func (m *DBClient) GetInstanceConfiguration(ctx context.Context, instanceId string) ([]connector.Configuration, error)

GetInstanceConfigurations returns all configuration parameters for the given instance id. If no parameters where found it return an empty slice.

func (*DBClient) GetInstances

func (m *DBClient) GetInstances(ctx context.Context) ([]*connector.Instance, error)

GetInstances returns all instances.

func (*DBClient) GetInstancesInstallationConfiguration added in v0.4.5

func (m *DBClient) GetInstancesInstallationConfiguration(ctx context.Context, instanceID string) ([]*connector.Configuration, error)

GetInstancesInstallationConfiguration retrieves the configuration of the installation of an instance

func (*DBClient) GetMappingByExternalId added in v0.4.5

func (m *DBClient) GetMappingByExternalId(ctx context.Context, instanceId string, externalID string) (*connector.ThingMapping, error)

GetMappingByExternalId searches for a thing mapping with specific external id

func (*DBClient) GetMappingByInstanceId

func (m *DBClient) GetMappingByInstanceId(ctx context.Context, instanceId string) ([]connector.ThingMapping, error)

GetMappingByInstanceId returns all things mapped to the instance with the given id.

func (*DBClient) Migrate

func (m *DBClient) Migrate() error

Migrate will execute all queries in MigrationQueries It returns error if any of the queries fails to execute. Migrate is not called by the default service but may be called once by the connector to initially migrate a database. Note that MigrationQueries can be overwritten.

func (*DBClient) RemoveInstallation

func (m *DBClient) RemoveInstallation(ctx context.Context, installationId string) error

RemoveInstallation removes the instance with the given id from the database. This will also remove instances belonging to this installation, as well as the configuration parameters. Removal of config parameters and instances is implemented via cascading foreign keys in the database. If your database does not support cascading foreign keys, you should delete them manually.

func (*DBClient) RemoveInstance

func (m *DBClient) RemoveInstance(ctx context.Context, instanceId string) error

RemoveInstance removes the instance with the given id from the database.

func (*DBClient) RemoveThingMapping added in v0.4.5

func (m *DBClient) RemoveThingMapping(ctx context.Context, instanceID string, thingID string) error

RemoveThingMapping removes a thing mapping with given instance and thing id

type DBDriverName

type DBDriverName string

type DBOptions

type DBOptions struct {
	Driver DBDriverName
	DSN    string
}

Jump to

Keyboard shortcuts

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