creatorupdatordeprecate
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package queryprocessor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func ParseDBNullType(qType repository.NullQuerytype) (Type, error) {
|
||||
if !qType.Valid {
|
||||
return TypeJsonExtractor, fmt.Errorf("invalid database query type")
|
||||
}
|
||||
|
||||
return ParseDBType(qType.Querytype)
|
||||
}
|
||||
|
||||
func ParseDBType(qType repository.Querytype) (Type, error) {
|
||||
switch qType {
|
||||
case repository.QuerytypeJsonExtractor:
|
||||
return TypeJsonExtractor, nil
|
||||
case repository.QuerytypeContextFull:
|
||||
return TypeContextFull, nil
|
||||
default:
|
||||
return TypeJsonExtractor, fmt.Errorf("invalid database query type")
|
||||
}
|
||||
}
|
||||
|
||||
func ToDBQueryType(t Type) (repository.NullQuerytype, error) {
|
||||
var dbType repository.Querytype
|
||||
|
||||
switch t {
|
||||
case TypeJsonExtractor:
|
||||
dbType = repository.QuerytypeJsonExtractor
|
||||
case TypeContextFull:
|
||||
dbType = repository.QuerytypeContextFull
|
||||
default:
|
||||
return repository.NullQuerytype{}, fmt.Errorf("invalid database query type")
|
||||
}
|
||||
|
||||
return repository.NullQuerytype{Querytype: dbType, Valid: true}, nil
|
||||
}
|
||||
|
||||
func ParseDBQuery(q *repository.GetCollectorQueriesRow) (*Query, error) {
|
||||
reqQueryIDs := make([]uuid.UUID, len(q.Requiredids))
|
||||
for index, id := range q.Requiredids {
|
||||
reqQueryIDs[index] = database.MustToUUID(id)
|
||||
}
|
||||
|
||||
qType, err := ParseDBNullType(q.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Query{
|
||||
ID: database.MustToUUID(q.Queryid),
|
||||
Version: q.Queryversion.Int32,
|
||||
Type: qType,
|
||||
RequiredQueryIDs: reqQueryIDs,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package queryprocessor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Type int
|
||||
|
||||
const (
|
||||
TypeJsonExtractor = iota
|
||||
TypeContextFull
|
||||
)
|
||||
|
||||
type Create struct {
|
||||
Type Type
|
||||
RequiredQueryIDs []uuid.UUID
|
||||
Config interface{}
|
||||
}
|
||||
|
||||
type Update struct {
|
||||
ID uuid.UUID
|
||||
RequiredQueryIDs []uuid.UUID
|
||||
Config interface{}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
ID uuid.UUID
|
||||
Type Type
|
||||
Version int32
|
||||
RequiredQueryIDs []uuid.UUID
|
||||
Config interface{}
|
||||
}
|
||||
|
||||
type Creator interface {
|
||||
Validate(ctx context.Context, entity *Create) error
|
||||
Create(ctx context.Context, entity *Create) (uuid.UUID, error)
|
||||
}
|
||||
|
||||
type Updator interface {
|
||||
Validate(ctx context.Context, entity *Update) error
|
||||
Update(ctx context.Context, entity *Update) error
|
||||
}
|
||||
|
||||
type Processor interface {
|
||||
Process(ctx context.Context, query Query, values *[]result.Value) (string, error)
|
||||
}
|
||||
Reference in New Issue
Block a user