110 lines
2.0 KiB
Go
110 lines
2.0 KiB
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/result"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Type int
|
|
|
|
const (
|
|
TypeJsonExtractor = iota
|
|
TypeContextFull
|
|
)
|
|
|
|
type QueryRow struct {
|
|
ID uuid.UUID
|
|
Type Type
|
|
RequiredQueryID uuid.UUID
|
|
Version int32
|
|
}
|
|
|
|
type Query struct {
|
|
ID uuid.UUID
|
|
Type Type
|
|
RequiredQueryIDs []uuid.UUID
|
|
Version int32
|
|
Config interface{}
|
|
}
|
|
|
|
type ListFilters struct {
|
|
Types []Type
|
|
}
|
|
|
|
type Create struct {
|
|
Type Type
|
|
RequiredQueryIDs []uuid.UUID
|
|
}
|
|
|
|
type Update struct {
|
|
ID uuid.UUID
|
|
}
|
|
|
|
type Test struct {
|
|
ID uuid.UUID
|
|
}
|
|
|
|
type Processor interface {
|
|
Process(ctx context.Context, query QueryRow, values *[]result.Value) (string, error)
|
|
}
|
|
|
|
type Service struct {
|
|
db *repository.Queries
|
|
}
|
|
|
|
func New(db *repository.Queries) *Service {
|
|
return &Service{db}
|
|
}
|
|
|
|
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Query, error) {
|
|
query, err := s.db.GetQuery(ctx, database.MustToDBUUID(id))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
queryType, err := ParseDBType(query.Type)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
reqIDs := make([]uuid.UUID, len(query.Requiredids))
|
|
for index, id := range query.Requiredids {
|
|
reqIDs[index] = database.MustToUUID(id)
|
|
}
|
|
|
|
return &Query{
|
|
ID: id,
|
|
Type: queryType,
|
|
Version: query.Activeversion,
|
|
RequiredQueryIDs: reqIDs,
|
|
Config: string(query.Config),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Service) List(ctx context.Context, filters ListFilters) (*[]Query, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (s *Service) Create(ctx context.Context, entity Create) (uuid.UUID, error) {
|
|
return uuid.Nil, nil
|
|
}
|
|
|
|
func (s *Service) Update(ctx context.Context, entity Update) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) Remove(ctx context.Context, id uuid.UUID) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) Test(ctx context.Context, filters Test) (string, error) {
|
|
// Sync doc
|
|
// Run test
|
|
|
|
return "", nil
|
|
}
|