Creating Datasource Plugins
Datasource plugins allow Evidence to connect to databases and data sources. This guide walks through creating a custom datasource plugin.Plugin Structure
A datasource plugin is an npm package that exports specific functions and configuration.Required Package Structure
Package Configuration
package.json
The first item in each datasources array is the canonical name shown in the UI. Additional items are aliases.
Required Exports
Every datasource plugin must export three main items:1. Query Runner Function
index.cjs
2. Get Runner Factory
3. Connection Tester
4. Options Schema
Options Schema Reference
Field Types
| Type | Description | Example |
|---|---|---|
string | Single-line text input | "localhost" |
multiline | Multi-line text area | SQL queries |
number | Numeric input | 5432 |
boolean | Checkbox | true / false |
select | Dropdown menu | List of options |
file | File upload | Certificate files |
Field Properties
Nested Options Example
Query Results Interface
Evidence Type Mapping
Map database types to Evidence types:Column Types Schema
Result Formats
Array Format
Generator Format (for large datasets)
Complete Example: PostgreSQL Plugin
Here’s a simplified version of the official PostgreSQL plugin:index.cjs
Development Workflow
Implement Plugin
Create
index.cjs with required exports:- Default export:
runQuery - Named exports:
getRunner,testConnection,options
Testing
Create a test file to verify your plugin:test/test.js
Best Practices
Error Handling
Type Parsing
Memory Management
Streaming Large Results
Publishing
Update Package Metadata
Ensure
package.json has:- Correct version
- Complete description
- Keywords including
evidence-datasource - License