evidence.datasources
postgres
, psql
, postgresql
, redshift
, and timescaledb
will all select this connectorpostgres
, redshift
, and timescaledb
will be presented as options in the UI.
{
"evidence": {
"datasources": [
[ "postgres", "psql", "postgresql" ], // Shows only `postgres` in the UI
"redshift",
"timescaledb"
]
}
}
index.js
defines the type ConnectorOptions
, and exports an options
constant.
ConnectorOptions
should be typed to the expected configuration for your datasource (e.g. hostname, port, etc)
options
defines how your connector will be configured in the UI, we recommend reading the docs, and/or taking a look at the Evidence Postgres Connector. Technically, implementing this is optional, but it provides a much better user experience when your datasource is installed.
Evidence accepts 2 different interfaces when using datasources, one is much easier to write, but is much less flexible.
Note that
lib.js
has a stubbeddatabaseTypeToEvidenceType
, which is helpful for buildingColumnTypes
more easily.
For the simple interface, implement the getRunner
function; which is a factory pattern for building a configured QueryRunner.
Each query can either return an array of results, or an async generator function if implementing cursor logic (this enables much larger datasets)
For the advanced interface, implement the processSource
function; which is an async generator function returning tables directly.
processSource
receives a proxy of the source's filetree, so it must look for files itself, but returns results in the same available formats as getRunner
. processSource
should be used in instances where output tables do not map one to one with input files (e.g. if a list of tables is provided in connection.yaml
that should all be SELECT *
'd)
This template comes with vitest
pre-installed. If you've used jest, vitest implements a very similar API.
Tests have been stubbed in index.spec.js
, and can be run with npm run test
Typescript has also been included with a basic configuration, and your types can be checked with npm run check
test-project
using npm i ../datasource
evidence.plugins.yaml
sources
, or in the settings ui.options
object, testing it in the settings UI is recommended.npm run sources
in the test project to execute your datasource, and modify index.md
to use your new source.
schema explorer
to make sure that the types returned