Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/famarks/sqlds
https://github.com/famarks/sqlds
Last synced: 12 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/famarks/sqlds
- Owner: famarks
- License: apache-2.0
- Created: 2024-01-17T06:27:15.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-01-17T06:46:02.000Z (12 months ago)
- Last Synced: 2024-11-07T15:17:35.253Z (2 months ago)
- Language: Go
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://drone.grafarg.net/api/badges/grafarg/sqlds/status.svg)](https://drone.grafarg.net/grafarg/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
ds := sqlds.NewDatasource(&myDatasource{})
if err := datasource.Manage("my-datasource", ds.NewDatasource, datasource.ManageOpts{}); err != nil {
log.DefaultLogger.Error(err.Error())
os.Exit(1)
}
```## Standardization
### Macros
The `sqlds` package defines a set of default macros:
- `$__timeFilter(time_column)`: Filters by timestamp using the query period. Resolves to: `time >= '0001-01-01T00:00:00Z' AND time <= '0001-01-01T00:00:00Z'`
- `$__timeFrom(time_column)`: Filters by timestamp using the start point of the query period. Resolves to `time >= '0001-01-01T00:00:00Z'`
- `$__timeTo(time_column)`: Filters by timestamp using the end point of the query period. Resolves to `time <= '0001-01-01T00:00:00Z'`
- `$__timeGroup(time_column, period)`: To group times based on a period. Resolves to (minute example): `"datepart(year, time), datepart(month, time)'"`
- `$__table`: Returns the `table` configured in the query.
- `$__column`: Returns the `column` configured in the query.