mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Create config to enable/disable query history * Create add to query history functionality * Add documentation * Add test * Refactor * Add test * Fix built errors and linting errors * Refactor * Remove old tests * Refactor, adjust based on feedback, add new test * Update default value
33 lines
767 B
Go
33 lines
767 B
Go
package queryhistory
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
"github.com/grafana/grafana/pkg/util"
|
|
)
|
|
|
|
func (s QueryHistoryService) createQuery(ctx context.Context, user *models.SignedInUser, cmd CreateQueryInQueryHistoryCommand) error {
|
|
queryHistory := QueryHistory{
|
|
OrgId: user.OrgId,
|
|
Uid: util.GenerateShortUID(),
|
|
Queries: cmd.Queries,
|
|
DatasourceUid: cmd.DatasourceUid,
|
|
CreatedBy: user.UserId,
|
|
CreatedAt: time.Now().Unix(),
|
|
Comment: "",
|
|
}
|
|
|
|
err := s.SQLStore.WithDbSession(ctx, func(session *sqlstore.DBSession) error {
|
|
_, err := session.Insert(&queryHistory)
|
|
return err
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|