This commit is contained in:
Michael McGuinness
2024-12-24 17:13:48 +00:00
parent 827d973053
commit 4dd050e390
46 changed files with 327 additions and 155 deletions
+3 -3
View File
@@ -2,8 +2,8 @@ package queryQueue
import (
"context"
"gotemplate/internal/database"
"gotemplate/internal/query"
"queryorchestration/internal/database"
"queryorchestration/internal/query"
)
func (q *Queue) getUnsyncedQueries() {
@@ -75,7 +75,7 @@ func (q *Queue) Add(qu *query.Query) {
}
if requiredIndex != -1 {
*q.unsyncedQueue = append((*q.unsyncedQueue)[:requiredIndex], append([]query.Query{*qu}, (*q.unsyncedQueue)[requiredIndex:]...)...)
*q.unsyncedQueue = append((*q.unsyncedQueue)[:requiredIndex+1], append([]query.Query{*qu}, (*q.unsyncedQueue)[requiredIndex+1:]...)...)
} else {
*q.unsyncedQueue = append([]query.Query{*qu}, *q.unsyncedQueue...)
}
+32 -6
View File
@@ -2,9 +2,13 @@ package queryQueue
import (
"context"
"gotemplate/internal/database"
"gotemplate/internal/query"
"gotemplate/internal/result"
"fmt"
contextfull "queryorchestration/internal/contextFull"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
jsonextractor "queryorchestration/internal/jsonExtractor"
"queryorchestration/internal/query"
"queryorchestration/internal/result"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
@@ -59,9 +63,13 @@ func (q *Queue) executeQuery(ctx context.Context, qu query.Query) error {
}
cleanValues := make([]result.Value, len(values))
for _, r := range values {
cleanValue := result.ParseValue(&r)
cleanValues = append(cleanValues, *cleanValue)
for index, r := range values {
cleanValue, err := q.getResultValue(&r)
if err != nil {
return err
}
cleanValues[index] = cleanValue
}
err = q.setResult(ctx, qu, &cleanValues)
@@ -71,3 +79,21 @@ func (q *Queue) executeQuery(ctx context.Context, qu query.Query) error {
return nil
}
func (q *Queue) getResultValue(res *repository.ListResultValuesByIDRow) (result.Value, error) {
var queryType query.Type
for _, qu := range *q.collectorQueries {
if qu.ID == database.MustToUUID(res.Queryid) {
queryType = qu.Type
}
}
switch queryType {
case query.TypeJsonExtractor:
return jsonextractor.NewResult(res.Value), nil
case query.TypeContextFull:
return contextfull.NewResult(res.Value), nil
default:
return nil, fmt.Errorf("attempting to process invalid query type")
}
}
+6 -3
View File
@@ -3,9 +3,10 @@ package queryQueue
import (
"context"
"fmt"
jsonextractor "gotemplate/internal/jsonExtractor"
"gotemplate/internal/query"
"gotemplate/internal/result"
contextfull "queryorchestration/internal/contextFull"
jsonextractor "queryorchestration/internal/jsonExtractor"
"queryorchestration/internal/query"
"queryorchestration/internal/result"
)
func (q *Queue) setResult(ctx context.Context, qu query.Query, resultValues *[]result.Value) error {
@@ -44,6 +45,8 @@ func (q *Queue) getProcessor(queryType query.Type) (query.Processor, error) {
switch queryType {
case query.TypeJsonExtractor:
return jsonextractor.New(q.db), nil
case query.TypeContextFull:
return contextfull.New(), nil
default:
return nil, fmt.Errorf("attempting to process invalid query type")
}
+4 -4
View File
@@ -2,10 +2,10 @@ package queryQueue
import (
"context"
"gotemplate/internal/collector"
"gotemplate/internal/database/repository"
"gotemplate/internal/query"
"gotemplate/internal/result"
"queryorchestration/internal/collector"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/query"
"queryorchestration/internal/result"
"github.com/google/uuid"
)