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
- Variables
- type DBClient
- func (m *DBClient) AddInstallation(ctx context.Context, installationRequest connector.InstallationRequest) error
- func (m *DBClient) AddInstallationConfiguration(ctx context.Context, installationId string, config []connector.Configuration) error
- func (m *DBClient) AddInstance(ctx context.Context, instantiationRequest connector.InstantiationRequest) error
- func (m *DBClient) AddInstanceConfiguration(ctx context.Context, instanceId string, config []connector.Configuration) error
- func (m *DBClient) AddThingMapping(ctx context.Context, instanceId string, thingId string, externalId string) error
- func (m *DBClient) GetInstallations(ctx context.Context) ([]*connector.Installation, error)
- func (m *DBClient) GetInstance(ctx context.Context, instanceId string) (*connector.Instance, error)
- func (m *DBClient) GetInstanceByThingId(ctx context.Context, thingId string) (*connector.Instance, error)
- func (m *DBClient) GetInstanceConfiguration(ctx context.Context, instanceId string) ([]connector.Configuration, error)
- func (m *DBClient) GetInstances(ctx context.Context) ([]*connector.Instance, error)
- func (m *DBClient) GetInstancesInstallationConfiguration(ctx context.Context, instanceID string) ([]*connector.Configuration, error)
- func (m *DBClient) GetMappingByExternalId(ctx context.Context, instanceId string, externalID string) (*connector.ThingMapping, error)
- func (m *DBClient) GetMappingByInstanceId(ctx context.Context, instanceId string) ([]connector.ThingMapping, error)
- func (m *DBClient) Migrate() error
- func (m *DBClient) RemoveInstallation(ctx context.Context, installationId string) error
- func (m *DBClient) RemoveInstance(ctx context.Context, instanceId string) error
- func (m *DBClient) RemoveThingMapping(ctx context.Context, instanceID string, thingID string) error
- type DBDriverName
- type DBOptions
Constants ¶
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 ¶
var ( DriverMysql = DBDriverName("mysql") DriverPostgresql = DBDriverName("postgres") DriverSqlite3 = DBDriverName("sqlite3") )
Supported database drivers:
var DefaultOptions = &DBOptions{ Driver: DriverSqlite3, DSN: "default.sqlite3", }
var MigrationQueries = []string{ StatementCreateInstallationTable, StatementCreateInstanceTable, StatementCreateInstaceThingMapping, StatementCreateInstallConfigTable, StatementCreateInstanceConfigTable, }
MigrationQueries will be executed when the connector calls Migrate:
Functions ¶
This section is empty.
Types ¶
type DBClient ¶
func NewDBClient ¶
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 ¶
GetInstallations returns a list of all existing installations together with their provided configuration parameters.
func (*DBClient) GetInstance ¶
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 ¶
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 ¶
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 ¶
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 ¶
RemoveInstance removes the instance with the given id from the database.
type DBDriverName ¶
type DBDriverName string
type DBOptions ¶
type DBOptions struct { Driver DBDriverName DSN string }