https://github.com/grafana/sqlds
A package that assists writing SQL-driven datasources
https://github.com/grafana/sqlds
group-datasources squad-big-tent-plugins squad-partner-plugins
Last synced: 5 months ago
JSON representation
A package that assists writing SQL-driven datasources
- Host: GitHub
- URL: https://github.com/grafana/sqlds
- Owner: grafana
- License: apache-2.0
- Created: 2020-09-20T22:04:28.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-05-12T14:40:04.000Z (5 months ago)
- Last Synced: 2025-05-12T15:26:19.423Z (5 months ago)
- Topics: group-datasources, squad-big-tent-plugins, squad-partner-plugins
- Language: Go
- Homepage:
- Size: 272 KB
- Stars: 24
- Watchers: 142
- Forks: 12
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[](https://drone.grafana.net/grafana/sqlds)
# sqlds
`sqlds` stands for `SQL Datasource`.
Most SQL-driven datasources, like `Postgres`, `MySQL`, and `MSSQL` share extremely similar codebases.
The `sqlds` package is intended to remove the repetition of these datasources and centralize the datasource logic. The only thing that the datasources themselves should have to define is connecting to the database, and what driver to use, and the plugin frontend.
**Usage**
```go
if err := datasource.Manage("my-datasource", datasourceFactory, datasource.ManageOpts{}); err != nil {
log.DefaultLogger.Error(err.Error())
os.Exit(1)
}func datasourceFactory(ctx context.Context, s backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
ds := sqlds.NewDatasource(&myDatasource{})
return ds.NewDatasource(ctx, s)
}
```## Standardization
### Macros
The `sqlds` package formerly defined a set of default macros, but those have been migrated to `grafana-plugin-sdk-go`: see [the code](https://github.com/grafana/grafana-plugin-sdk-go/blob/main/data/sqlutil/macros.go) for details.