The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/stores/sqlstore/sqlstore_datasource.go

48 lines
899 B

package sqlstore
import (
"time"
"github.com/torkelo/grafana-pro/pkg/bus"
m "github.com/torkelo/grafana-pro/pkg/models"
"github.com/go-xorm/xorm"
)
func init() {
bus.AddHandler("sql", GetDataSources)
bus.AddHandler("sql", AddDataSource)
}
func GetDataSources(query *m.GetDataSourcesQuery) error {
sess := x.Limit(100, 0).Where("account_id=?", query.AccountId)
query.Resp = make([]*m.DataSource, 0)
return sess.Find(&query.Resp)
}
func AddDataSource(cmd *m.AddDataSourceCommand) error {
return inTransaction(func(sess *xorm.Session) error {
var err error
ds := m.DataSource{
AccountId: cmd.AccountId,
Name: cmd.Name,
Type: cmd.Type,
Access: cmd.Access,
Url: cmd.Url,
Created: time.Now(),
Updated: time.Now(),
}
if ds.Id == 0 {
_, err = sess.Insert(ds)
} else {
_, err = sess.Id(ds.Id).Update(ds)
}
return err
})
}