Extending the Connections Pane
The Connections Pane can be extended by:
- Adding support for browsing and managing a new connection type in the Connections Pane.
- Extending the “New connections” modal to support creating a connection of a new type.
Adding new connection types
In R, you can extend connection types using the RStudio connections contract. Refer to the RStudio connections contract documentation for more information on how to implement a new connection type.
For Python, we don’t currently support an external extension mechanism. The Connections Pane can be extended by implementing a subclass of the Connection
class (defined in connections.py
) and submitting a PR to the Positron repository. Refer to SQLite3Connection
for an example.
Extending the “New connections” modal
The “New connections” modal allows users to easily create connections to different databases. It helps users create a connection by providing a form to fill in the connection details.
The modal can be extended by creating an extension for Positron; see Extension Development for more information.
In order for an extension to provide support for a new connection type, it needs to implement and register a positron.ConnectionsDriver
. A driver provides metadata about the connection type and implements callbacks that are used to install dependencies required to create the connection, connect with the database, and disconnect.
The definition can be found in positron.d.ts; look for ConnectionsDriver
.
export interface ConnectionsDriver {
/**
* The unique identifier for the driver.
*/
: string;
driverId
/**
* The metadata for the driver.
*/
: ConnectionsDriverMetadata;
metadata
/**
* Generates the connection code based on the inputs.
*/
?: (inputs: Array<ConnectionsInput>) => string;
generateCode
/**
* Connect session.
*/
?: (code: string) => Promise<void>;
connect
/**
* Checks if the dependencies for the driver are installed
* and functioning.
*/
?: () => Promise<boolean>;
checkDependencies
/**
* Installs the dependencies for the driver.
* For instance, R packages would install the required
* R packages, and or other dependencies.
*/
?: () => Promise<boolean>;
installDependencies }
To register a driver, extensions need to call positron.connections.registerConnectionDriver()
with the driver instance as an argument.
Refer to drivers.ts for examples of drivers implemented in the Positron Connections extension.