package
0.0.0-20230822162846-6698953c95a9
Repository: https://github.com/tuneinsight/sdk-datasource.git
Documentation: pkg.go.dev

# README

SDK

Data source plugin for the Tune Insight Note

A TI Note data source plugin extends the data manager to allow clients to query external data sources. It exposes operations that can have arbitrary parameters and results, and can potentially output data objects.

How to develop a data source plugin

A TI Note data source plugin is a Go plugin that exposes two variables:

  • DataSourceType a string (of the type sdk.DataSourceType) that identifies uniquely the type of data source.
  • DataSourcePluginFactory a function (of the type sdk.DataSourcePluginFactory) that can be invoked by the TI Note to create a new instance of the data source.

The factory function sdk.DataSourcePluginFactory takes as parameters:

  • logger that allows the data source plugin logging to be integrated with the one of the TI Note;
  • config a map of arbitrary config keys to allow the data source to be configured by the TI Note.

It returns a data source, which is a struct that implements the interface sdk.DataSourcePlugin with the function Query(). This function takes as arguments:

  • userID the unique identifier of the user invoking the query;
  • operation the operation requested for the query;
  • jsonParameters the parameters of the operation, that can be anything in the JSON format;
  • outputDataObjectsSharedIDs the shared IDs defined by the client the potential output data objects of the operation should have.

The Query() function returns:

  • jsonResults the results of the operation, that can be anything in the JSON format;
  • outputDataObjects the potential output data objects of the operation;
  • err the potential error of the operation.

If the operation outputs data objects, those must be of the type sdk.DataObject, with the shared ID and output name provided by the client.

Use the plugin in Tune Insight Note

The plugin compiled into a .so file must be placed under the plugins/datasources directory of the TI Note. The plugin is then dynamically loaded at TI Note startup, after which it will be possible to instantiate, query, and manage data sources of the newly defined type throug the TI Note API.

# Packages

No description provided by the author
No description provided by the author

# Functions

Checksum returns the checksum of a connection configuration which is created using the datasource name and the driver name.
DataImpl is the function that should be called by all Data() implementations.
IsRegistered returns whether or not the given db-driver is already registered.
NewAPI creates a new API instance given configuration,connection, and parameters for connection attempts.
NewConnection opens a new sql.DB connection given the configuration, if the driver is not yet registered it gets registered.
NewDatabase creates a new Database instance given configuration,connection, and parameters for connection attempts.
NewDataSourceCore instantiates a DataSourceCore with the provided @mdb and @mds.
NewDBManager creates a new manager with an empty map of databases.
NewMetadataDB instantiates a MetadataDB given the required fields.
NewMetadataStorage instantiates a default MetadataStorage.
WrapErrors wraps multiple errors into a single error message.

# Constants

DefaultResultKey is the default key of the results returned by `Query`.
DSCoreMetadataField is the key under which the MetadataStorage are stored in the TI Note storage.
OutputDataObjectsKey is the key for the data object IDs generated by the data source results.
QueryOperation is the operation key.
QueryParams is the parameters key.

# Structs

API is composed of the a logger and API configuration.
Database is composed of a *sql.DB, logger and Database configuration.
DatabaseError is wraps a database-related error.
DataObject defines a data object to be produced by a DataSourcePlugin.
DataSourceCore contains the common DataSource metadata.
DBManager manages live database connections.
DBManagerConfig regroups parameters for connection to all databases.
GenericAPIConfig is the configuration for a generic HTTP API.
MetadataDB contains the common DataSource metadata that are stored in the TI Note database.
MetadataStorage contains the common DataSource metadata that are stored in the TI Note object storage.
PostgresConfig is the configuration when using the postgres driver.
SQLiteConfig is the configuration when using the sqlite driver.

# Interfaces

APIConfig is a general interface for specific api configs, from the specific config, the API name and URL can be retrieved as well as the datasource name to use the API.
DatabaseConfig is a general interface for specific-db configs, from the specific config, the driver name can be retrieved as well as the datasource name to connect to the db and a function to register the actual driver.
DataSource defines a TI Note data source, which is instantiated by a DataSourceFactory.

# Type aliases

DataSourceFactory defines a TI Note data source factory, which is a function that can instantiate a DataSource.
DataSourceType defines a data source type, which uniquely identifies a data source plugin.
OutputDataObjectName is a name for a data object that was output by a DataSourcePlugin.Query.