How to extend the built-in PostgreSQL plugin

I’m currently working on a task where, in essence, I’d like to reimplement Grafana’s bundled PostgreSQL plugin as a third-party/external plugin, and then adjust its functionality (specifically, some additions + simplifications to the query builder, and some changes to the configuration)

This can be done by adding the changes to a new core plugin folder, then building grafana from source, but this is somewhat cumbersome, and every time grafana updates, it will be necessary to build from source again to get the new updates.

Instead, I’ve been working on implementing the interface with the new React third party plugin structure.

Upon reaching the backend, however, I’ve hit a blocking point.
To reimplement the postgres functionality, it seems it will be necessary to copy the postgres go files (such as locker_test.go, tlsmanager.go, etc) from <grafana>\pkg\tsdb\postgres to <plugins>\<my_plugin>\pkg, or possibly <plugins>\<my_plugin>\pkg\plugin>, adapting the applicable endpoints to integrate better with the current third-party plugin API (adding a checkhealth method in the go files instead of having the testDatasource method in datasource.ts, for example)

However, when moving these files into the plugin folder, after running go mod tidy to update dependencies, some imports are causing problems, eg

package main
import (

Running go mod tidy, the following sort of error appears in the error log: imports module found (v6.1.6+incompatible), but does not contain package

Basically, for several packages, it attempts to import them from module found (v6.1.6+incompatible), but does not find them

How would I go about fixing this? The core plugin files manage to import these packages, so they are accessible somewhere. Or is there some other way to get the functionality defined in those modules in the third party plugin? Or perhaps further, is there some other way of implementing the existing core PostgreSQL plugin such that Grafana can be updated without necessitating that Grafana be rebuilt from source each time it updates?

Unfortunately, built-in (core) data sources and panels use internal packages that aren’t available to standalone plugins. This makes them hard to implement as third-party plugins.

It might be easier to build a new plugin that uses sqlds or one that proxies the data request to the built-in data source.