grafana/pkg/services/queryhistory/models.go
Ivana Huckova 6e96506c23
Query history: Add search functionality (#45932)
* Query history: Add search functionality

* Add more tests

* Add documentation

* Fix spell errors

* Update docs

* Update docs

* Fix lint error

* Update docs/sources/http_api/query_history.md

Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>

* Document limit

* Run tests with postgres and mysql

* Use CASE insted of IIF

* Use BooleanStr instead of 1

* Change LIKE to LikeStr()

* Return back integration tests

* Update SQL to use Bool() everywhere

* Create new tests for sorting

* Update docs/sources/http_api/query_history.md

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Update docs/sources/http_api/query_history.md

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Update docs/sources/http_api/query_history.md

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Update docs/sources/http_api/query_history.md

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Update docs/sources/http_api/query_history.md

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Add page, count and limit to results

* Remove newline

* Update documentation

* Update docs

Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>
Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
2022-03-07 12:28:04 +01:00

81 lines
2.4 KiB
Go

package queryhistory
import (
"errors"
"github.com/grafana/grafana/pkg/components/simplejson"
)
var (
ErrQueryNotFound = errors.New("query in query history not found")
ErrStarredQueryNotFound = errors.New("starred query not found")
ErrQueryAlreadyStarred = errors.New("query was already starred")
)
type QueryHistory struct {
ID int64 `xorm:"pk autoincr 'id'"`
UID string `xorm:"uid"`
DatasourceUID string `xorm:"datasource_uid"`
OrgID int64 `xorm:"org_id"`
CreatedBy int64
CreatedAt int64
Comment string
Queries *simplejson.Json
}
type QueryHistoryStar struct {
ID int64 `xorm:"pk autoincr 'id'"`
QueryUID string `xorm:"query_uid"`
UserID int64 `xorm:"user_id"`
}
type CreateQueryInQueryHistoryCommand struct {
DatasourceUID string `json:"datasourceUid"`
Queries *simplejson.Json `json:"queries"`
}
type SearchInQueryHistoryQuery struct {
DatasourceUIDs []string `json:"datasourceUids"`
SearchString string `json:"searchString"`
OnlyStarred bool `json:"onlyStarred"`
Sort string `json:"sort"`
Page int `json:"page"`
Limit int `json:"limit"`
}
type PatchQueryCommentInQueryHistoryCommand struct {
Comment string `json:"comment"`
}
type QueryHistoryDTO struct {
UID string `json:"uid" xorm:"uid"`
DatasourceUID string `json:"datasourceUid" xorm:"datasource_uid"`
CreatedBy int64 `json:"createdBy"`
CreatedAt int64 `json:"createdAt"`
Comment string `json:"comment"`
Queries *simplejson.Json `json:"queries"`
Starred bool `json:"starred"`
}
// QueryHistoryResponse is a response struct for QueryHistoryDTO
type QueryHistoryResponse struct {
Result QueryHistoryDTO `json:"result"`
}
type QueryHistorySearchResult struct {
TotalCount int `json:"totalCount"`
QueryHistory []QueryHistoryDTO `json:"queryHistory"`
Page int `json:"page"`
PerPage int `json:"perPage"`
}
type QueryHistorySearchResponse struct {
Result QueryHistorySearchResult `json:"result"`
}
// DeleteQueryFromQueryHistoryResponse is the response struct for deleting a query from query history
type DeleteQueryFromQueryHistoryResponse struct {
ID int64 `json:"id"`
Message string `json:"message"`
}