mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package datastore
|
|
|
|
import (
|
|
"github.com/kolide/kolide-ose/server/errors"
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
|
)
|
|
|
|
func (orm gormDB) NewQuery(query *kolide.Query) (*kolide.Query, error) {
|
|
if query == nil {
|
|
return nil, errors.New(
|
|
"error creating query",
|
|
"nil pointer passed to NewQuery",
|
|
)
|
|
}
|
|
err := orm.DB.Create(query).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return query, nil
|
|
}
|
|
|
|
func (orm gormDB) SaveQuery(query *kolide.Query) error {
|
|
if query == nil {
|
|
return errors.New(
|
|
"error saving query",
|
|
"nil pointer passed to SaveQuery",
|
|
)
|
|
}
|
|
return orm.DB.Save(query).Error
|
|
}
|
|
|
|
func (orm gormDB) DeleteQuery(query *kolide.Query) error {
|
|
if query == nil {
|
|
return errors.New(
|
|
"error deleting query",
|
|
"nil pointer passed to DeleteQuery",
|
|
)
|
|
}
|
|
return orm.DB.Delete(query).Error
|
|
}
|
|
|
|
func (orm gormDB) Query(id uint) (*kolide.Query, error) {
|
|
query := &kolide.Query{
|
|
ID: id,
|
|
}
|
|
err := orm.DB.Where(query).First(query).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return query, nil
|
|
}
|
|
|
|
func (orm gormDB) ListQueries(opt kolide.ListOptions) ([]*kolide.Query, error) {
|
|
var queries []*kolide.Query
|
|
err := orm.applyListOptions(opt).Find(&queries).Error
|
|
return queries, err
|
|
}
|