Merged in feature/serviceconfig-integration (pull request #38)
DRAFT PR : WIP working through ideas for integration * movearound * attempttwo * openapi * further sanding * fix * start on tests * runthroughsingleconfig * somechanges * reflectissue * removeerrs * mostlyremovepanic * removeenv * noncfgtests * go * repo * fix service config test * add PWD to all * test fix * fix lint * todo for later * passingunittests * alltests * testlogger * testloggername * clean
This commit is contained in:
@@ -31,7 +31,7 @@ type DocumentQueryEvent struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
}
|
||||
|
||||
func (s QueryRunner) Process(ctx context.Context, req *types.Message) error {
|
||||
func (s *QueryRunner) Process(ctx context.Context, req *types.Message) error {
|
||||
var body query.Document
|
||||
err := json.Unmarshal([]byte(*req.Body), &body)
|
||||
if err != nil {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/query/result"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
@@ -26,16 +27,15 @@ func TestQueryRunner(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
|
||||
svc := query.New(db, &query.Services{
|
||||
Result: result.New(db),
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := query.New(cfg, &query.Services{
|
||||
Result: result.New(cfg),
|
||||
Text: documenttext.New(),
|
||||
Collector: collector.New(db, &collector.Services{}),
|
||||
Collector: collector.New(cfg, &collector.Services{}),
|
||||
})
|
||||
|
||||
runner := controllers.NewQueryRunner(validator.New(), &controllers.Services{
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -24,14 +25,13 @@ func TestCreateClient(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Client: client.New(db),
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
body := queryservice.ClientCreate{
|
||||
@@ -64,14 +64,13 @@ func TestGetClient(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Client: client.New(db),
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
e := echo.New()
|
||||
@@ -107,14 +106,13 @@ func TestUpdateClient(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Client: client.New(db),
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
cs := false
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
documenttext "queryorchestration/internal/document/text"
|
||||
"queryorchestration/internal/job"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -29,16 +30,15 @@ func TestCreateJob(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
extract := documenttext.New()
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Job: job.New(db, &job.Services{
|
||||
Collector: collector.New(db, &collector.Services{
|
||||
Job: job.New(cfg, &job.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{
|
||||
Clean: documentclean.New(),
|
||||
Text: extract,
|
||||
}),
|
||||
@@ -81,15 +81,13 @@ func TestGetJob(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Job: job.New(db, &job.Services{
|
||||
Client: client.New(db),
|
||||
Job: job.New(cfg, &job.Services{
|
||||
Client: client.New(cfg),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -133,15 +131,13 @@ func TestUpdateJob(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Job: job.New(db, &job.Services{
|
||||
Client: client.New(db),
|
||||
Job: job.New(cfg, &job.Services{
|
||||
Client: client.New(cfg),
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
documentclean "queryorchestration/internal/document/clean"
|
||||
documenttext "queryorchestration/internal/document/text"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -26,11 +27,9 @@ func TestUpdateJobCollector(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
av := int32(2)
|
||||
body := queryservice.JobCollectorUpdate{
|
||||
@@ -47,7 +46,7 @@ func TestUpdateJobCollector(t *testing.T) {
|
||||
|
||||
extract := documenttext.New()
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Collector: collector.New(db, &collector.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{
|
||||
Clean: documentclean.New(),
|
||||
Text: extract,
|
||||
}),
|
||||
@@ -83,11 +82,9 @@ func TestGetJobCollectorByJobId(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
e := echo.New()
|
||||
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
|
||||
@@ -95,7 +92,7 @@ func TestGetJobCollectorByJobId(t *testing.T) {
|
||||
ctx := e.NewContext(req, rec)
|
||||
|
||||
extract := documenttext.New()
|
||||
svc := collector.New(db, &collector.Services{
|
||||
svc := collector.New(cfg, &collector.Services{
|
||||
Clean: documentclean.New(),
|
||||
Text: extract,
|
||||
})
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/query/result"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -31,14 +32,12 @@ func TestCreateQuery(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Query: query.New(db, &query.Services{}),
|
||||
Query: query.New(cfg, &query.Services{}),
|
||||
})
|
||||
|
||||
body := queryservice.QueryCreate{
|
||||
@@ -73,14 +72,12 @@ func TestListQueries(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Query: query.New(db, &query.Services{}),
|
||||
Query: query.New(cfg, &query.Services{}),
|
||||
})
|
||||
|
||||
e := echo.New()
|
||||
@@ -118,14 +115,12 @@ func TestGetQuery(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Query: query.New(db, &query.Services{}),
|
||||
Query: query.New(cfg, &query.Services{}),
|
||||
})
|
||||
|
||||
e := echo.New()
|
||||
@@ -162,14 +157,12 @@ func TestUpdateQuery(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Query: query.New(db, &query.Services{}),
|
||||
Query: query.New(cfg, &query.Services{}),
|
||||
})
|
||||
|
||||
av := int32(2)
|
||||
@@ -210,23 +203,21 @@ func TestTestQuery(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
docsvc := document.New(db)
|
||||
col := collector.New(db, &collector.Services{
|
||||
docsvc := document.New(cfg)
|
||||
col := collector.New(cfg, &collector.Services{
|
||||
Clean: documentclean.New(),
|
||||
Text: documenttext.New(),
|
||||
})
|
||||
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
|
||||
Collector: col,
|
||||
Query: query.New(db, &query.Services{
|
||||
Query: query.New(cfg, &query.Services{
|
||||
Document: docsvc,
|
||||
Collector: col,
|
||||
Result: result.New(db),
|
||||
Result: result.New(cfg),
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
+3
-1
@@ -19,7 +19,9 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
|
||||
|
||||
FROM scratch AS final
|
||||
|
||||
WORKDIR /app
|
||||
ENV PWD=/app
|
||||
|
||||
WORKDIR ${PWD}
|
||||
|
||||
COPY database/migrations/ database/migrations/
|
||||
|
||||
|
||||
+27
-12
@@ -2,14 +2,17 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
controllers "queryorchestration/api/queryRunner"
|
||||
"queryorchestration/internal/document"
|
||||
documentclean "queryorchestration/internal/document/clean"
|
||||
documenttext "queryorchestration/internal/document/text"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/query/result"
|
||||
"queryorchestration/internal/server"
|
||||
"queryorchestration/internal/server/queue"
|
||||
"queryorchestration/internal/server/runner"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
@@ -17,29 +20,41 @@ import (
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
queryrunner := func(cfg *server.Config) queue.Controller {
|
||||
extract := documenttext.New()
|
||||
cfg := &runner.BaseConfig{}
|
||||
|
||||
if err := serviceconfig.InitializeConfig(cfg); err != nil {
|
||||
slog.Error("Error initializing config", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cfg.ControllerFunc = func() runner.Controller {
|
||||
text := documenttext.New()
|
||||
clean := documentclean.New()
|
||||
coll := collector.New(cfg.Database, &collector.Services{
|
||||
coll := collector.New(cfg, &collector.Services{
|
||||
Text: text,
|
||||
Clean: clean,
|
||||
})
|
||||
res := result.New(cfg.Database)
|
||||
svc := query.New(cfg.Database, &query.Services{
|
||||
res := result.New(cfg)
|
||||
doc := document.New(cfg)
|
||||
svc := query.New(cfg, &query.Services{
|
||||
Result: res,
|
||||
Text: extract,
|
||||
Text: text,
|
||||
Collector: coll,
|
||||
Document: doc,
|
||||
})
|
||||
|
||||
return controllers.NewQueryRunner(cfg.Validator, &controllers.Services{
|
||||
c := controllers.NewQueryRunner(cfg.GetValidator(), &controllers.Services{
|
||||
Query: svc,
|
||||
})
|
||||
|
||||
return &c
|
||||
}
|
||||
|
||||
server := queue.NewServer(ctx, &queue.ListenerConfig{
|
||||
Controller: queryrunner,
|
||||
})
|
||||
server, err := runner.New(ctx, cfg)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
server.Listen(ctx)
|
||||
}
|
||||
|
||||
+32
-20
@@ -2,9 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
queryservice "queryorchestration/api/queryService"
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/document"
|
||||
documentclean "queryorchestration/internal/document/clean"
|
||||
documenttext "queryorchestration/internal/document/text"
|
||||
"queryorchestration/internal/export"
|
||||
@@ -12,32 +15,41 @@ import (
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/query/result"
|
||||
"queryorchestration/internal/server"
|
||||
"queryorchestration/internal/server/api"
|
||||
service "queryorchestration/internal/server/service"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
registerHandlers := func(cfg *server.Config, e *echo.Echo) *api.APIConfig {
|
||||
exp := export.New(cfg.Database)
|
||||
cfg := &service.BaseConfig{}
|
||||
|
||||
if err := serviceconfig.InitializeConfig(cfg); err != nil {
|
||||
fmt.Printf("Error initializing config: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cfg.RegisterHandlersFunc = func() (*openapi3.T, error) {
|
||||
exp := export.New()
|
||||
extract := documenttext.New()
|
||||
clean := documentclean.New()
|
||||
col := collector.New(cfg.Database, &collector.Services{
|
||||
res := result.New(cfg)
|
||||
col := collector.New(cfg, &collector.Services{
|
||||
Text: extract,
|
||||
Clean: clean,
|
||||
})
|
||||
res := result.New(cfg.Database)
|
||||
que := query.New(cfg.Database, &query.Services{
|
||||
doc := document.New(cfg)
|
||||
que := query.New(cfg, &query.Services{
|
||||
Text: extract,
|
||||
Result: res,
|
||||
Collector: col,
|
||||
Document: doc,
|
||||
})
|
||||
cli := client.New(cfg.Database)
|
||||
jbb := job.New(cfg.Database, &job.Services{
|
||||
cli := client.New(cfg)
|
||||
jbb := job.New(cfg, &job.Services{
|
||||
Collector: col,
|
||||
Client: cli,
|
||||
})
|
||||
@@ -50,23 +62,23 @@ func main() {
|
||||
Job: jbb,
|
||||
}
|
||||
|
||||
cons := queryservice.NewControllers(cfg.Validator, services)
|
||||
cons := queryservice.NewControllers(cfg.GetValidator(), services)
|
||||
|
||||
queryservice.RegisterHandlersWithBaseURL(e, cons, "")
|
||||
queryservice.RegisterHandlersWithBaseURL(cfg.Router, cons, "")
|
||||
|
||||
swagger, err := queryservice.GetSwagger()
|
||||
if err != nil {
|
||||
log.Panicf("Error loading swagger: %s", err)
|
||||
return nil, fmt.Errorf("error loading swagger: %s", err)
|
||||
}
|
||||
|
||||
return &api.APIConfig{
|
||||
Swagger: swagger,
|
||||
}
|
||||
return swagger, nil
|
||||
}
|
||||
|
||||
server := api.New(ctx, &api.Config{
|
||||
RegisterHandlers: registerHandlers,
|
||||
})
|
||||
server, err := service.New(ctx, cfg)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
server.Listen()
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
)
|
||||
|
||||
// Note: All that a service needs to have its own config is to create a new
|
||||
// config type (any name you want) and add your customer variables to it that
|
||||
// then call the serviceconfig.InitializeConfig() function on it.
|
||||
type AnyServiceNameConfig struct {
|
||||
// BaseConfig has all of the common base configuration that all services should have
|
||||
// we can adjust what is in there as needed.
|
||||
serviceconfig.BaseConfig // Embed the base configuration
|
||||
|
||||
// add any custom values that this service needs
|
||||
AppEnv string `env:"APP_ENV"`
|
||||
}
|
||||
|
||||
// main
|
||||
// Dead simple example of of how to initialize a service custom config - AnyServiceNameConfig object in any project code.
|
||||
func main() {
|
||||
|
||||
// create your own customer service config
|
||||
cfg := &AnyServiceNameConfig{}
|
||||
// and let the shared code initialize it for you correctly.
|
||||
if err := serviceconfig.InitializeConfig(cfg); err != nil {
|
||||
fmt.Printf("Error initializing the custom config (see output): %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("config: %+v\n", cfg)
|
||||
cfg.Logger.Info("Service initialized ok.")
|
||||
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
"DB_HOST": "localhost",
|
||||
"DB_PORT": "5432",
|
||||
"DB_NAME": "query_orchestration",
|
||||
"DB_NOSSL": "1"
|
||||
"DB_NOSSL": "true"
|
||||
},
|
||||
"env_from": ".env"
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@ You can also edit live with https://mermaid.live
|
||||
|
||||
This diagram should be updated manually when there are changes to the database schema.
|
||||
|
||||
To generate the diagram directly use the following command:
|
||||
```bash
|
||||
docker run --rm -v $(pwd):/data minlag/mermaid-cli -i /data/diagram.mmd -o /data/output.png -w 1024 -H 768
|
||||
```
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
clients ||--o{ jobs : has
|
||||
|
||||
@@ -13,7 +13,7 @@ func (s *Service) Create(ctx context.Context, name string) (uuid.UUID, error) {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
id, err := s.db.Queries.CreateClient(ctx, name)
|
||||
id, err := s.cfg.GetDBQueries().CreateClient(ctx, name)
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -19,13 +20,11 @@ func TestCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(db)
|
||||
svc := client.New(cfg)
|
||||
|
||||
name := "client_name"
|
||||
aid := uuid.New()
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Client, error) {
|
||||
client, err := s.db.Queries.GetClient(ctx, database.MustToDBUUID(id))
|
||||
client, err := s.cfg.GetDBQueries().GetClient(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,13 +21,11 @@ func TestGet(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(db)
|
||||
svc := client.New(cfg)
|
||||
|
||||
id := uuid.New()
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package client
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@@ -70,11 +70,11 @@ func normalizeName(name *string) error {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
db *database.Connection
|
||||
cfg serviceconfig.ConfigProvider
|
||||
}
|
||||
|
||||
func New(db *database.Connection) *Service {
|
||||
func New(cfg serviceconfig.ConfigProvider) *Service {
|
||||
return &Service{
|
||||
db,
|
||||
cfg,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package client_test
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -15,12 +15,10 @@ func TestService(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(db)
|
||||
svc := client.New(cfg)
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (s *Service) Update(ctx context.Context, entity *Update) error {
|
||||
}
|
||||
|
||||
func (s *Service) submitUpdate(ctx context.Context, entity *Update) error {
|
||||
return database.ExecuteTransaction(ctx, s.db, func(ctx context.Context, q *repository.Queries) error {
|
||||
return s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
|
||||
id := database.MustToDBUUID(entity.ID)
|
||||
|
||||
if entity.Name != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -18,13 +19,11 @@ func TestUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := New(db)
|
||||
svc := New(cfg)
|
||||
|
||||
c := Client{
|
||||
ID: uuid.New(),
|
||||
@@ -119,13 +118,11 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := New(db)
|
||||
svc := New(cfg)
|
||||
|
||||
c := Client{
|
||||
ID: uuid.New(),
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMustGetURIInvalidPort(t *testing.T) {
|
||||
t.Setenv("DB_USER", "user")
|
||||
t.Setenv("DB_PASS", "pass")
|
||||
t.Setenv("DB_HOST", "host")
|
||||
t.Setenv("DB_PORT", "port")
|
||||
t.Setenv("DB_NAME", "name")
|
||||
|
||||
assert.Panics(t, func() { mustGetURI() })
|
||||
}
|
||||
|
||||
func TestMustGetURINoSSL(t *testing.T) {
|
||||
t.Setenv("DB_USER", "user")
|
||||
t.Setenv("DB_PASS", "pass")
|
||||
t.Setenv("DB_HOST", "host")
|
||||
t.Setenv("DB_PORT", "5432")
|
||||
t.Setenv("DB_NAME", "name")
|
||||
t.Setenv("DB_NOSSL", "1")
|
||||
|
||||
connStr := mustGetURI()
|
||||
assert.Equal(t, "postgres://user:pass@host:5432/name?sslmode=disable", connStr.String())
|
||||
}
|
||||
|
||||
func TestMustGetURINoEnv(t *testing.T) {
|
||||
t.Setenv("DB_USER", "")
|
||||
t.Setenv("DB_PASS", "")
|
||||
t.Setenv("DB_HOST", "")
|
||||
t.Setenv("DB_PORT", "")
|
||||
t.Setenv("DB_NAME", "")
|
||||
|
||||
assert.Panics(t, func() { mustGetURI() })
|
||||
}
|
||||
|
||||
func TestGetPoolConfig(t *testing.T) {
|
||||
t.Setenv("DB_USER", "user")
|
||||
t.Setenv("DB_PASS", "pass")
|
||||
t.Setenv("DB_HOST", "host")
|
||||
t.Setenv("DB_PORT", "5432")
|
||||
t.Setenv("DB_NAME", "name")
|
||||
|
||||
config, err := getPoolConfig()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, config.ConnString(), mustGetURI().String())
|
||||
}
|
||||
|
||||
func TestMustGetPoolConfig(t *testing.T) {
|
||||
t.Setenv("DB_USER", "user")
|
||||
t.Setenv("DB_PASS", "pass")
|
||||
t.Setenv("DB_HOST", "host")
|
||||
t.Setenv("DB_PORT", "5432")
|
||||
t.Setenv("DB_NAME", "name")
|
||||
|
||||
config := mustGetPoolConfig()
|
||||
assert.Equal(t, config.ConnString(), mustGetURI().String())
|
||||
}
|
||||
|
||||
func TestMustGetPoolConfigInvalidPort(t *testing.T) {
|
||||
t.Setenv("DB_USER", "user")
|
||||
t.Setenv("DB_PASS", "pass")
|
||||
t.Setenv("DB_HOST", "host")
|
||||
t.Setenv("DB_PORT", "invalid_port")
|
||||
t.Setenv("DB_NAME", "name")
|
||||
|
||||
assert.Panics(t, func() { mustGetPoolConfig() })
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/server/env"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
user string
|
||||
password string
|
||||
host string
|
||||
port nat.Port
|
||||
name string
|
||||
disableSSL bool
|
||||
}
|
||||
|
||||
func mustGetConfig() *config {
|
||||
user := env.GetPanic("DB_USER")
|
||||
pass := env.GetPanic("DB_PASS")
|
||||
host := env.GetPanic("DB_HOST")
|
||||
port := env.GetPanic("DB_PORT")
|
||||
natPort, err := nat.NewPort("tcp", port)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to create port: %v", err)
|
||||
}
|
||||
name := env.GetPanic("DB_NAME")
|
||||
|
||||
disableSSL, _ := env.Get("DB_NOSSL")
|
||||
|
||||
return &config{
|
||||
user: user,
|
||||
password: pass,
|
||||
host: host,
|
||||
port: natPort,
|
||||
name: name,
|
||||
disableSSL: disableSSL == "1",
|
||||
}
|
||||
}
|
||||
|
||||
func mustGetURI() *url.URL {
|
||||
driver := "postgres"
|
||||
conf := mustGetConfig()
|
||||
opts := ""
|
||||
|
||||
if conf.disableSSL {
|
||||
opts += "sslmode=disable"
|
||||
}
|
||||
|
||||
connStr := fmt.Sprintf("%s://%s:%s@%s:%d/%s?%s", driver, conf.user, conf.password, conf.host, conf.port.Int(), conf.name, opts)
|
||||
|
||||
uri, err := url.Parse(connStr)
|
||||
if err != nil {
|
||||
log.Panicf("Unable to parse URI: %s", err)
|
||||
}
|
||||
|
||||
return uri
|
||||
}
|
||||
|
||||
func getPoolConfig() (*pgxpool.Config, error) {
|
||||
connStr := mustGetURI()
|
||||
|
||||
config, err := pgxpool.ParseConfig(connStr.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
enumTypes := []string{
|
||||
"querytype",
|
||||
}
|
||||
|
||||
config.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
|
||||
for _, enumName := range enumTypes {
|
||||
dt, err := conn.LoadType(ctx, enumName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load suitable enum type: %w", err)
|
||||
}
|
||||
conn.TypeMap().RegisterType(dt)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func mustGetPoolConfig() *pgxpool.Config {
|
||||
config, err := getPoolConfig()
|
||||
if err != nil {
|
||||
log.Panicf("Unable to create database config: %v\n", err)
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
func GetDBPool(ctx context.Context) *pgxpool.Pool {
|
||||
config := mustGetPoolConfig()
|
||||
|
||||
pool, err := pgxpool.NewWithConfig(ctx, config)
|
||||
if err != nil {
|
||||
log.Panicf("Unable to create database pool: %v\n", err)
|
||||
}
|
||||
|
||||
return pool
|
||||
}
|
||||
|
||||
func ExecuteTransaction(ctx context.Context, db *Connection, executeQueries func(context.Context, *repository.Queries) error) error {
|
||||
tx, err := db.Pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = tx.Rollback(ctx)
|
||||
}()
|
||||
|
||||
qtx := db.Queries.WithTx(tx)
|
||||
|
||||
err = executeQueries(ctx, qtx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Commit(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
_ "github.com/golang-migrate/migrate/v4/database/postgres"
|
||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
func createDB() {
|
||||
driver := "postgres"
|
||||
conf := mustGetConfig()
|
||||
|
||||
opts := ""
|
||||
if conf.disableSSL {
|
||||
opts += "sslmode=disable"
|
||||
}
|
||||
|
||||
connStr := fmt.Sprintf("%s://%s:%s@%s:%d/?%s", driver, conf.user, conf.password, conf.host, conf.port.Int(), opts)
|
||||
|
||||
db, err := sql.Open("postgres", connStr)
|
||||
if err != nil {
|
||||
log.Panicf("Error opening database: %v", err)
|
||||
}
|
||||
|
||||
err = db.Ping()
|
||||
if err != nil {
|
||||
log.Panicf("Error pinging database: %v", err)
|
||||
}
|
||||
|
||||
rs, err := db.Query(fmt.Sprintf("SELECT 'CREATE DATABASE %s' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '%s')", conf.name, conf.name))
|
||||
if err != nil {
|
||||
log.Panicf("Error creating database: %v", err)
|
||||
}
|
||||
|
||||
if rs.Next() {
|
||||
log.Printf("Database created: %s", conf.name)
|
||||
} else {
|
||||
log.Printf("Database already exists: %s", conf.name)
|
||||
}
|
||||
}
|
||||
|
||||
type MigrationConfig struct {
|
||||
BasePath string
|
||||
}
|
||||
|
||||
func RunMigrations(ctx context.Context, config *MigrationConfig) {
|
||||
createDB()
|
||||
|
||||
connStr := mustGetURI()
|
||||
|
||||
basePath := config.BasePath
|
||||
if basePath == "" {
|
||||
basePath = os.Getenv("PWD")
|
||||
}
|
||||
|
||||
migPath := "file://" + path.Join(basePath, "database/migrations")
|
||||
m, err := migrate.New(
|
||||
migPath,
|
||||
connStr.String(),
|
||||
)
|
||||
if err != nil {
|
||||
log.Panicf("failed to create migrate instance: %v", err)
|
||||
}
|
||||
|
||||
err = m.Up()
|
||||
if err == migrate.ErrNoChange {
|
||||
log.Println("No changes required")
|
||||
} else if err != nil {
|
||||
log.Panicf("failed to apply migrations: %v", err)
|
||||
} else {
|
||||
log.Println("Migrations applied successfully!")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"path"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
_ "github.com/golang-migrate/migrate/v4/database/postgres"
|
||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
func createDB(cfg serviceconfig.ConfigProvider) error {
|
||||
connStr := fmt.Sprintf("%s?%s", cfg.GetDBBaseURI(), cfg.GetDBOptsString())
|
||||
|
||||
db, err := sql.Open(cfg.GetDBDriver(), connStr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error opening database: %v", err)
|
||||
}
|
||||
|
||||
err = db.Ping()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error pinging database: %v", err)
|
||||
}
|
||||
|
||||
rs, err := db.Query(fmt.Sprintf("SELECT 'CREATE DATABASE %s' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '%s')", cfg.GetDBName(), cfg.GetDBName()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating database: %v", err)
|
||||
}
|
||||
|
||||
if !rs.Next() {
|
||||
slog.Info("database created", "name", cfg.GetDBName())
|
||||
} else {
|
||||
slog.Info("database already exists", "name", cfg.GetDBName())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, cfg serviceconfig.ConfigProvider) error {
|
||||
err := createDB(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
migPath := "file://" + path.Join(cfg.GetBasePath(), "database/migrations")
|
||||
m, err := migrate.New(
|
||||
migPath,
|
||||
cfg.GetDBURI(),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create migrate instance: %v", err)
|
||||
}
|
||||
|
||||
err = m.Up()
|
||||
if err == migrate.ErrNoChange {
|
||||
slog.Info("No migration changes required")
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("failed to apply migrations: %v", err)
|
||||
} else {
|
||||
slog.Info("Migrations applied successfully!")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+20
-12
@@ -1,10 +1,11 @@
|
||||
package database_test
|
||||
package migrations_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/migrations"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
@@ -17,12 +18,18 @@ func TestRunMigrations(t *testing.T) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{})
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
database.RunMigrations(ctx, &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../.."),
|
||||
})
|
||||
err = migrations.Run(ctx, cfg)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestRunMigrationsNoDB(t *testing.T) {
|
||||
@@ -33,11 +40,12 @@ func TestRunMigrationsNoDB(t *testing.T) {
|
||||
t.Setenv("DB_HOST", "invalid_host")
|
||||
t.Setenv("DB_PORT", "5432")
|
||||
t.Setenv("DB_NAME", "invalid_name")
|
||||
t.Setenv("DB_NOSSL", "1")
|
||||
t.Setenv("DB_NOSSL", "true")
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.Panics(t, func() {
|
||||
database.RunMigrations(ctx, &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../.."),
|
||||
})
|
||||
})
|
||||
err = migrations.Run(ctx, cfg)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateDB(t *testing.T) {
|
||||
t.Setenv("DB_HOST", "invalid_value")
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = createDB(cfg)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateDB(t *testing.T) {
|
||||
t.Setenv("DB_HOST", "")
|
||||
|
||||
assert.Panics(t, func() { createDB() })
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database/repository"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type Pool interface {
|
||||
Begin(ctx context.Context) (pgx.Tx, error)
|
||||
}
|
||||
|
||||
type Connection struct {
|
||||
Pool Pool
|
||||
Queries *repository.Queries
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
@@ -14,13 +14,19 @@ import (
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
id, err := queries.CreateClient(ctx, "example_client")
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"path"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
@@ -16,13 +17,19 @@ import (
|
||||
|
||||
func TestCollector(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
contextId, err := queries.CreateQuery(ctx, repository.QuerytypeContextFull)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
@@ -14,13 +14,19 @@ import (
|
||||
|
||||
func TestDocument(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
clientId, err := queries.CreateClient(ctx, "example_client")
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
@@ -14,13 +14,18 @@ import (
|
||||
|
||||
func TestJob(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
clientId, err := queries.CreateClient(ctx, "example_client")
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"path"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
@@ -16,14 +17,18 @@ import (
|
||||
|
||||
func TestQueries(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
contextQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeContextFull))
|
||||
assert.Nil(t, err)
|
||||
@@ -162,13 +167,18 @@ func TestQueries(t *testing.T) {
|
||||
func TestQueryDependencyTree(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
contextQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeContextFull))
|
||||
assert.Nil(t, err)
|
||||
@@ -230,13 +240,18 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
func TestQueriesList(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: "../../..",
|
||||
}})
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
contextQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeContextFull))
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
@@ -16,13 +16,18 @@ import (
|
||||
func TestResults(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
jsonQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeJsonExtractor))
|
||||
assert.Nil(t, err)
|
||||
@@ -72,13 +77,18 @@ func TestResults(t *testing.T) {
|
||||
func TestResultValues(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
jsonQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeJsonExtractor))
|
||||
assert.Nil(t, err)
|
||||
@@ -167,13 +177,18 @@ func TestResultValues(t *testing.T) {
|
||||
func TestUnsyncedQueries(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
db, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Migrations: &database.MigrationConfig{
|
||||
BasePath: path.Join(os.Getenv("PWD"), "../../.."),
|
||||
}})
|
||||
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
err := serviceconfig.InitializeConfig(cfg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
queries := repository.New(db.Pool)
|
||||
queries := cfg.DBQueries
|
||||
|
||||
clientId, err := queries.CreateClient(ctx, "example_client")
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -21,7 +21,7 @@ func (s *Service) Create(ctx context.Context, doc *Create) (uuid.UUID, error) {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
dbid, err := s.db.Queries.CreateDocument(ctx, &repository.CreateDocumentParams{
|
||||
dbid, err := s.cfg.GetDBQueries().CreateDocument(ctx, &repository.CreateDocumentParams{
|
||||
Jobid: database.MustToDBUUID(doc.JobID),
|
||||
Hash: hash,
|
||||
Location: doc.Location,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -19,13 +20,11 @@ func TestCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := document.New(db)
|
||||
svc := document.New(cfg)
|
||||
|
||||
doc := document.Document{
|
||||
ID: uuid.New(),
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Document, error) {
|
||||
doc, err := s.db.Queries.GetDocument(ctx, database.MustToDBUUID(id))
|
||||
doc, err := s.cfg.GetDBQueries().GetDocument(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -19,13 +20,11 @@ func TestGet(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := document.New(db)
|
||||
svc := document.New(cfg)
|
||||
|
||||
doc := document.Document{
|
||||
ID: uuid.New(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -14,11 +14,11 @@ type Document struct {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
db *database.Connection
|
||||
cfg serviceconfig.ConfigProvider
|
||||
}
|
||||
|
||||
func New(db *database.Connection) *Service {
|
||||
func New(cfg serviceconfig.ConfigProvider) *Service {
|
||||
return &Service{
|
||||
db,
|
||||
cfg,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
package export
|
||||
|
||||
import "queryorchestration/internal/database"
|
||||
|
||||
type Service struct {
|
||||
db *database.Connection
|
||||
}
|
||||
|
||||
func New(db *database.Connection) *Service {
|
||||
return &Service{
|
||||
db,
|
||||
}
|
||||
func New() *Service {
|
||||
return &Service{}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,13 @@
|
||||
package export_test
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/export"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
pool, err := pgxmock.NewPool()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
|
||||
svc := export.New(db)
|
||||
svc := export.New()
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -38,18 +38,6 @@ type dbCreateParams struct {
|
||||
Fields *map[string]pgtype.UUID
|
||||
}
|
||||
|
||||
type fields struct {
|
||||
values *[]uuid.UUID
|
||||
}
|
||||
|
||||
func (f *fields) GetRequiredQueryIDs() *[]uuid.UUID {
|
||||
return f.values
|
||||
}
|
||||
|
||||
func (f *fields) SetRequiredQueryIDs(v *[]uuid.UUID) {
|
||||
f.values = v
|
||||
}
|
||||
|
||||
func (s *Service) getCreateParams(ctx context.Context, params *CreateParams) (*dbCreateParams, error) {
|
||||
minClean := params.MinCleanVersion
|
||||
if minClean != nil {
|
||||
@@ -82,7 +70,7 @@ func (s *Service) getCreateParams(ctx context.Context, params *CreateParams) (*d
|
||||
|
||||
func (s *Service) submitCreate(ctx context.Context, params *dbCreateParams) (uuid.UUID, error) {
|
||||
var dbID pgtype.UUID
|
||||
err := database.ExecuteTransaction(ctx, s.db, func(ctx context.Context, qtx *repository.Queries) error {
|
||||
err := s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, qtx *repository.Queries) error {
|
||||
dID, err := qtx.CreateCollector(ctx, params.JobID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,13 +21,11 @@ func TestCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := collector.New(db, &collector.Services{})
|
||||
svc := collector.New(cfg, &collector.Services{})
|
||||
|
||||
id := uuid.New()
|
||||
minCleanV := int32(2)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,14 +21,12 @@ func TestGetCreateParams(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
svc: &Services{},
|
||||
}
|
||||
|
||||
@@ -71,14 +70,12 @@ func TestSubmitCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
svc: &Services{},
|
||||
}
|
||||
|
||||
@@ -109,13 +106,3 @@ func TestSubmitCreate(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, id, aid)
|
||||
}
|
||||
|
||||
func TestFields(t *testing.T) {
|
||||
f := fields{}
|
||||
assert.Nil(t, f.GetRequiredQueryIDs())
|
||||
|
||||
values := []uuid.UUID{uuid.New()}
|
||||
f.SetRequiredQueryIDs(&values)
|
||||
assert.NotNil(t, f.values)
|
||||
assert.ElementsMatch(t, *f.values, *f.GetRequiredQueryIDs())
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Collector, error) {
|
||||
dbColl, err := s.db.Queries.GetCollector(ctx, database.MustToDBUUID(id))
|
||||
dbColl, err := s.cfg.GetDBQueries().GetCollector(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -18,7 +18,7 @@ func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Collector, error) {
|
||||
}
|
||||
|
||||
func (s *Service) GetByJobID(ctx context.Context, jobID uuid.UUID) (*Collector, error) {
|
||||
dbColl, err := s.db.Queries.GetCollectorByJobID(ctx, database.MustToDBUUID(jobID))
|
||||
dbColl, err := s.cfg.GetDBQueries().GetCollectorByJobID(ctx, database.MustToDBUUID(jobID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func (s *Service) GetByJobID(ctx context.Context, jobID uuid.UUID) (*Collector,
|
||||
}
|
||||
|
||||
func (s *Service) ListQueries(ctx context.Context, id uuid.UUID) ([]*resultprocessor.Query, error) {
|
||||
queries, err := s.db.Queries.ListCollectorQueries(ctx, database.MustToDBUUID(id))
|
||||
queries, err := s.cfg.GetDBQueries().ListCollectorQueries(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,13 +21,11 @@ func TestGet(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := collector.New(db, &collector.Services{})
|
||||
svc := collector.New(cfg, &collector.Services{})
|
||||
|
||||
minCleanV := int32(2)
|
||||
minTextV := int32(4)
|
||||
@@ -58,13 +57,11 @@ func TestGetByJobID(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := collector.New(db, &collector.Services{})
|
||||
svc := collector.New(cfg, &collector.Services{})
|
||||
|
||||
minCleanV := int32(2)
|
||||
minTextV := int32(4)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package collector
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
documentclean "queryorchestration/internal/document/clean"
|
||||
documenttext "queryorchestration/internal/document/text"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -24,13 +24,13 @@ type Services struct {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
db *database.Connection
|
||||
cfg serviceconfig.ConfigProvider
|
||||
svc *Services
|
||||
}
|
||||
|
||||
func New(db *database.Connection, svc *Services) *Service {
|
||||
func New(cfg serviceconfig.ConfigProvider, svc *Services) *Service {
|
||||
return &Service{
|
||||
db,
|
||||
cfg,
|
||||
svc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package collector_test
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -15,12 +15,10 @@ func TestService(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := collector.New(db, &collector.Services{})
|
||||
svc := collector.New(cfg, &collector.Services{})
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ func (s *Service) normalizeFieldsToDB(ctx context.Context, ofields *map[string]u
|
||||
return nil, errors.New("duplicate output fields")
|
||||
}
|
||||
|
||||
exist, err := s.db.Queries.AllQueriesExist(ctx, dbids)
|
||||
exist, err := s.cfg.GetDBQueries().AllQueriesExist(ctx, dbids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !exist {
|
||||
@@ -166,7 +166,7 @@ func (s *Service) normalizeFieldsToDB(ctx context.Context, ofields *map[string]u
|
||||
}
|
||||
|
||||
func (s *Service) submitUpdate(ctx context.Context, current *Collector, params *dbUpdateParams) error {
|
||||
err := database.ExecuteTransaction(ctx, s.db, func(ctx context.Context, qtx *repository.Queries) error {
|
||||
err := s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, qtx *repository.Queries) error {
|
||||
latestVersion := current.LatestVersion + 1
|
||||
id := database.MustToDBUUID(current.ID)
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
documentclean "queryorchestration/internal/document/clean"
|
||||
documenttext "queryorchestration/internal/document/text"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -22,13 +23,11 @@ func TestUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := collector.New(db, &collector.Services{
|
||||
svc := collector.New(cfg, &collector.Services{
|
||||
Clean: documentclean.New(),
|
||||
Text: documenttext.New(),
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
documentclean "queryorchestration/internal/document/clean"
|
||||
documenttext "queryorchestration/internal/document/text"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -22,14 +23,12 @@ func TestGetUpdateParams(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
svc: &Services{},
|
||||
}
|
||||
|
||||
@@ -86,14 +85,12 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
svc: &Services{},
|
||||
}
|
||||
|
||||
@@ -155,14 +152,12 @@ func TestNormalizeFieldsToDB(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
svc: &Services{},
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Service) Create(ctx context.Context, clientID uuid.UUID) (uuid.UUID, error) {
|
||||
did, err := s.db.Queries.CreateJob(ctx, database.MustToDBUUID(clientID))
|
||||
did, err := s.cfg.GetDBQueries().CreateJob(ctx, database.MustToDBUUID(clientID))
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/job"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -21,14 +22,12 @@ func TestCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := job.New(db, &job.Services{
|
||||
Collector: collector.New(db, &collector.Services{}),
|
||||
svc := job.New(cfg, &job.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{}),
|
||||
})
|
||||
|
||||
job := job.Job{
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Job, error) {
|
||||
job, err := s.db.Queries.GetJob(ctx, database.MustToDBUUID(id))
|
||||
job, err := s.cfg.GetDBQueries().GetJob(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/job"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -21,15 +22,13 @@ func TestGet(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := job.New(db, &job.Services{
|
||||
Collector: collector.New(db, &collector.Services{}),
|
||||
Client: client.New(db),
|
||||
svc := job.New(cfg, &job.Services{
|
||||
Collector: collector.New(cfg, &collector.Services{}),
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
j := job.Job{
|
||||
|
||||
@@ -2,8 +2,8 @@ package job
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -20,13 +20,13 @@ type Services struct {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
db *database.Connection
|
||||
cfg serviceconfig.ConfigProvider
|
||||
svc *Services
|
||||
}
|
||||
|
||||
func New(db *database.Connection, svc *Services) *Service {
|
||||
func New(cfg serviceconfig.ConfigProvider, svc *Services) *Service {
|
||||
return &Service{
|
||||
db,
|
||||
cfg,
|
||||
svc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package job_test
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/job"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -15,12 +15,10 @@ func TestService(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := job.New(db, &job.Services{})
|
||||
svc := job.New(cfg, &job.Services{})
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (s *Service) normalizeUpdate(ctx context.Context, current *Job, update *Upd
|
||||
}
|
||||
|
||||
func (s *Service) submitUpdate(ctx context.Context, update *Update) error {
|
||||
err := database.ExecuteTransaction(ctx, s.db, func(ctx context.Context, q *repository.Queries) error {
|
||||
err := s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
|
||||
if update.CanSync != nil {
|
||||
err := q.AddJobCanSync(ctx, &repository.AddJobCanSyncParams{
|
||||
Jobid: database.MustToDBUUID(update.ID),
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/job"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,14 +21,12 @@ func TestUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := job.New(db, &job.Services{
|
||||
Client: client.New(db),
|
||||
svc := job.New(cfg, &job.Services{
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
j := job.Job{
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -19,14 +20,12 @@ func TestNormalizeCanSync(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := New(db, &Services{
|
||||
Client: client.New(db),
|
||||
svc := New(cfg, &Services{
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
j := Job{
|
||||
@@ -99,14 +98,12 @@ func TestNormalizeUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := New(db, &Services{
|
||||
Client: client.New(db),
|
||||
svc := New(cfg, &Services{
|
||||
Client: client.New(cfg),
|
||||
})
|
||||
|
||||
j := Job{
|
||||
@@ -134,14 +131,12 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
j := Job{
|
||||
|
||||
@@ -58,7 +58,7 @@ func (s *Service) submitCreate(ctx context.Context, entity *resultprocessor.Crea
|
||||
}
|
||||
|
||||
var dbID pgtype.UUID
|
||||
err = database.ExecuteTransaction(ctx, s.db, func(ctx context.Context, qtx *repository.Queries) error {
|
||||
err = s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, qtx *repository.Queries) error {
|
||||
dbID, err = qtx.CreateQuery(ctx, query.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -106,9 +106,9 @@ func (s *Service) submitCreate(ctx context.Context, entity *resultprocessor.Crea
|
||||
func (s *Service) getCreator(qType resultprocessor.Type) (resultprocessor.Creator, error) {
|
||||
switch qType {
|
||||
case resultprocessor.TypeJsonExtractor:
|
||||
return jsonextractor.NewCreator(s.db), nil
|
||||
return jsonextractor.NewCreator(), nil
|
||||
case resultprocessor.TypeContextFull:
|
||||
return contextfull.NewCreator(s.db), nil
|
||||
return contextfull.NewCreator(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("attempting to process invalid query type")
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -22,12 +23,10 @@ func TestCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := query.New(db, &query.Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := query.New(cfg, &query.Services{})
|
||||
|
||||
config := "{\"path\":\"example_path\"}"
|
||||
q := query.Query{
|
||||
@@ -76,12 +75,10 @@ func TestCreateMinimal(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := query.New(db, &query.Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := query.New(cfg, &query.Services{})
|
||||
|
||||
q := query.Query{
|
||||
ID: uuid.New(),
|
||||
@@ -113,12 +110,10 @@ func TestCreateRollback(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := query.New(db, &query.Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := query.New(cfg, &query.Services{})
|
||||
|
||||
create := &resultprocessor.Create{
|
||||
Type: resultprocessor.TypeJsonExtractor,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -18,12 +19,10 @@ func TestGetCreator(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := New(db, &Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := New(cfg, &Services{})
|
||||
|
||||
queryType := resultprocessor.Type(resultprocessor.TypeContextFull)
|
||||
creator, err := svc.getCreator(queryType)
|
||||
@@ -82,12 +81,10 @@ func TestSubmitCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := New(db, &Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := New(cfg, &Services{})
|
||||
|
||||
config := "{\"path\":\"example_path\"}"
|
||||
q := Query{
|
||||
@@ -132,12 +129,10 @@ func TestSubmitCreateNoReqsOrConfig(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := New(db, &Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := New(cfg, &Services{})
|
||||
|
||||
q := Query{
|
||||
ID: uuid.New(),
|
||||
@@ -169,12 +164,10 @@ func TestNormalizeCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := New(db, &Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := New(cfg, &Services{})
|
||||
|
||||
create := &resultprocessor.Create{
|
||||
Type: resultprocessor.TypeJsonExtractor,
|
||||
|
||||
@@ -19,7 +19,7 @@ type Query struct {
|
||||
}
|
||||
|
||||
func (s *Service) GetWithVersion(ctx context.Context, id uuid.UUID, version int32) (*Query, error) {
|
||||
query, err := s.db.Queries.GetQueryWithVersion(ctx, &repository.GetQueryWithVersionParams{
|
||||
query, err := s.cfg.GetDBQueries().GetQueryWithVersion(ctx, &repository.GetQueryWithVersionParams{
|
||||
ID: database.MustToDBUUID(id),
|
||||
Addedversion: version,
|
||||
})
|
||||
@@ -31,7 +31,7 @@ func (s *Service) GetWithVersion(ctx context.Context, id uuid.UUID, version int3
|
||||
}
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Query, error) {
|
||||
query, err := s.db.Queries.GetQuery(ctx, database.MustToDBUUID(id))
|
||||
query, err := s.cfg.GetDBQueries().GetQuery(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,12 +21,10 @@ func TestGet(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := query.New(db, &query.Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := query.New(cfg, &query.Services{})
|
||||
|
||||
config := "{\"path\":\"example_path\"}"
|
||||
query := query.Query{
|
||||
@@ -59,12 +58,10 @@ func TestGetWithVersion(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := query.New(db, &query.Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := query.New(cfg, &query.Services{})
|
||||
|
||||
config := "{\"path\":\"example_path\"}"
|
||||
query := query.Query{
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Service) List(ctx context.Context) ([]*Query, error) {
|
||||
dbQueries, err := s.db.Queries.ListQueries(ctx)
|
||||
dbQueries, err := s.cfg.GetDBQueries().ListQueries(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -22,7 +22,7 @@ func (s *Service) List(ctx context.Context) ([]*Query, error) {
|
||||
}
|
||||
|
||||
func (s *Service) ListById(ctx context.Context, ids []uuid.UUID) ([]*Query, error) {
|
||||
dbQueries, err := s.db.Queries.ListQueriesById(ctx, database.MustToDBUUIDArray(ids))
|
||||
dbQueries, err := s.cfg.GetDBQueries().ListQueriesById(ctx, database.MustToDBUUIDArray(ids))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -21,12 +22,10 @@ func TestList(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := query.New(db, &query.Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := query.New(cfg, &query.Services{})
|
||||
|
||||
config := "{\"path\":\"example_path\"}"
|
||||
q := &query.Query{
|
||||
@@ -60,12 +59,10 @@ func TestListById(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := query.New(db, &query.Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := query.New(cfg, &query.Services{})
|
||||
|
||||
config := "{\"path\":\"example_path\"}"
|
||||
q := &query.Query{
|
||||
|
||||
@@ -73,7 +73,7 @@ func (s *Service) NormalizeQueryIDs(ctx context.Context, ids RequiredQueryIDs) e
|
||||
|
||||
dbids := database.MustToDBUUIDArray(dedup)
|
||||
|
||||
exist, err := s.db.Queries.AllQueriesExist(ctx, dbids)
|
||||
exist, err := s.cfg.GetDBQueries().AllQueriesExist(ctx, dbids)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !exist {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -74,12 +75,10 @@ func TestNormalizeQueryIDs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
s := Service{db: db}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
s := Service{cfg: cfg}
|
||||
|
||||
err = s.NormalizeQueryIDs(ctx, nil)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -22,7 +22,7 @@ type GetValueWithVersionParams struct {
|
||||
}
|
||||
|
||||
func (s *Service) GetValueWithVersion(ctx context.Context, params *GetValueWithVersionParams) (resultprocessor.Value, error) {
|
||||
res, err := s.db.Queries.GetResultValueWithVersion(ctx, &repository.GetResultValueWithVersionParams{
|
||||
res, err := s.cfg.GetDBQueries().GetResultValueWithVersion(ctx, &repository.GetResultValueWithVersionParams{
|
||||
Queryid: database.MustToDBUUID(params.QueryID),
|
||||
Queryversion: params.QueryVersion,
|
||||
Documentid: database.MustToDBUUID(params.DocumentID),
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -34,12 +35,11 @@ func TestGetValueWithVersion(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := New(db)
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := New(cfg)
|
||||
|
||||
params := &GetValueWithVersionParams{
|
||||
Type: resultprocessor.TypeJsonExtractor,
|
||||
|
||||
@@ -18,7 +18,7 @@ type ListQueryRequirementValuesParams struct {
|
||||
}
|
||||
|
||||
func (s *Service) ListQueryRequirementValues(ctx context.Context, params *ListQueryRequirementValuesParams) (*[]resultprocessor.Value, error) {
|
||||
qResults, err := s.db.Queries.ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
qResults, err := s.cfg.GetDBQueries().ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
Queryid: database.MustToDBUUID(params.QueryID),
|
||||
Documentid: database.MustToDBUUID(params.DocumentID),
|
||||
Addedversion: params.QueryVersion,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -21,13 +22,11 @@ func TestListQueryRequirementValues(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
params := &ListQueryRequirementValuesParams{
|
||||
|
||||
@@ -61,7 +61,7 @@ func (s *Service) listRequiredValues(ctx context.Context, p *Process) (*[]result
|
||||
func (s *Service) getProcessor(queryType resultprocessor.Type) (resultprocessor.Processor, error) {
|
||||
switch queryType {
|
||||
case resultprocessor.TypeJsonExtractor:
|
||||
return jsonextractor.NewExtractor(s.db), nil
|
||||
return jsonextractor.NewExtractor(s.cfg), nil
|
||||
case resultprocessor.TypeContextFull:
|
||||
return contextfull.NewExtractor(), nil
|
||||
default:
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -21,17 +22,15 @@ func TestProcess(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
cfg := "{\"path\":\"examplekey\"}"
|
||||
qcfg := "{\"path\":\"examplekey\"}"
|
||||
params := Process{
|
||||
DocumentID: uuid.New(),
|
||||
MinCleanVersion: 1,
|
||||
@@ -39,7 +38,7 @@ func TestProcess(t *testing.T) {
|
||||
Query: &resultprocessor.Query{
|
||||
ID: uuid.New(),
|
||||
Version: 2,
|
||||
Config: &cfg,
|
||||
Config: &qcfg,
|
||||
RequiredQueryIDs: &[]uuid.UUID{
|
||||
uuid.New(),
|
||||
},
|
||||
@@ -53,7 +52,7 @@ func TestProcess(t *testing.T) {
|
||||
)
|
||||
pool.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(params.Query.ID), params.Query.Version).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(cfg)),
|
||||
AddRow(pgtype.UUID{}, []byte(qcfg)),
|
||||
)
|
||||
|
||||
val, err := svc.Process(ctx, ¶ms)
|
||||
@@ -69,14 +68,12 @@ func TestListRequiredValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
pr, err := svc.listRequiredValues(ctx, nil)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package result
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -13,11 +13,11 @@ type Result struct {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
db *database.Connection
|
||||
cfg serviceconfig.ConfigProvider
|
||||
}
|
||||
|
||||
func New(db *database.Connection) *Service {
|
||||
func New(cfg serviceconfig.ConfigProvider) *Service {
|
||||
return &Service{
|
||||
db,
|
||||
cfg,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package result_test
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query/result"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -15,11 +15,9 @@ func TestService(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := result.New(db)
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := result.New(cfg)
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func (s *Service) Set(ctx context.Context, params *Set) (uuid.UUID, error) {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
dbId, err := s.db.Queries.SetResult(ctx, &repository.SetResultParams{
|
||||
dbId, err := s.cfg.GetDBQueries().SetResult(ctx, &repository.SetResultParams{
|
||||
Queryid: database.MustToDBUUID(params.Query.ID),
|
||||
Documentid: database.MustToDBUUID(params.DocumentID),
|
||||
Value: value.GetStoreValue(),
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,18 +21,16 @@ func TestSet(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
rid := uuid.New()
|
||||
cfg := "{\"path\":\"examplekey\"}"
|
||||
qcfg := "{\"path\":\"examplekey\"}"
|
||||
params := Set{
|
||||
DocumentID: uuid.New(),
|
||||
CleanVersion: 1,
|
||||
@@ -39,7 +38,7 @@ func TestSet(t *testing.T) {
|
||||
Query: &resultprocessor.Query{
|
||||
ID: uuid.New(),
|
||||
Version: 2,
|
||||
Config: &cfg,
|
||||
Config: &qcfg,
|
||||
RequiredQueryIDs: &[]uuid.UUID{
|
||||
uuid.New(),
|
||||
},
|
||||
@@ -53,7 +52,7 @@ func TestSet(t *testing.T) {
|
||||
)
|
||||
pool.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(params.Query.ID), params.Query.Version).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(cfg)),
|
||||
AddRow(pgtype.UUID{}, []byte(qcfg)),
|
||||
)
|
||||
pool.ExpectQuery("name: SetResult :one").WithArgs(database.MustToDBUUID(params.Query.ID), database.MustToDBUUID(params.DocumentID), pgxmock.AnyArg(), params.CleanVersion, params.TextVersion, params.Query.Version).
|
||||
WillReturnRows(
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Service) ListUnsyncedQueriesByDocId(ctx context.Context, id uuid.UUID) ([]*resultprocessor.Query, error) {
|
||||
qs, err := s.db.Queries.ListUnsyncedQueriesByDocId(ctx, database.MustToDBUUID(id))
|
||||
qs, err := s.cfg.GetDBQueries().ListUnsyncedQueriesByDocId(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query/result"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -21,12 +22,10 @@ func TestListUnsyncedQueriesByDocId(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := result.New(db)
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := result.New(cfg)
|
||||
|
||||
documentId := uuid.New()
|
||||
actualQs := []*resultprocessor.Query{
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/document"
|
||||
documenttext "queryorchestration/internal/document/text"
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/query/result"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -18,13 +18,13 @@ type Services struct {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
db *database.Connection
|
||||
cfg serviceconfig.ConfigProvider
|
||||
svc *Services
|
||||
}
|
||||
|
||||
func New(db *database.Connection, svc *Services) *Service {
|
||||
func New(cfg serviceconfig.ConfigProvider, svc *Services) *Service {
|
||||
return &Service{
|
||||
db,
|
||||
cfg,
|
||||
svc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package query_test
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -15,11 +15,9 @@ func TestService(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := query.New(db, &query.Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := query.New(cfg, &query.Services{})
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/query/result"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -186,14 +187,12 @@ func TestProcessBatch(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := Service{
|
||||
svc: &Services{
|
||||
Result: result.New(db),
|
||||
Result: result.New(cfg),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -246,14 +245,12 @@ func TestSync(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := Service{
|
||||
svc: &Services{
|
||||
Result: result.New(db),
|
||||
Result: result.New(cfg),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"queryorchestration/internal/job/collector"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/query/result"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -25,23 +26,21 @@ func TestTest(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
text := documenttext.New()
|
||||
clean := documentclean.New()
|
||||
col := collector.New(db, &collector.Services{
|
||||
col := collector.New(cfg, &collector.Services{
|
||||
Text: text,
|
||||
Clean: clean,
|
||||
})
|
||||
docsvc := document.New(db)
|
||||
svc := query.New(db, &query.Services{
|
||||
docsvc := document.New(cfg)
|
||||
svc := query.New(cfg, &query.Services{
|
||||
Text: text,
|
||||
Document: docsvc,
|
||||
Collector: col,
|
||||
Result: result.New(db),
|
||||
Result: result.New(cfg),
|
||||
})
|
||||
|
||||
coll := collector.Collector{
|
||||
|
||||
@@ -2,19 +2,17 @@ package contextfull
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
)
|
||||
|
||||
type Creator struct {
|
||||
db *database.Connection
|
||||
}
|
||||
|
||||
func NewCreator(db *database.Connection) Creator {
|
||||
return Creator{db}
|
||||
func NewCreator() *Creator {
|
||||
return &Creator{}
|
||||
}
|
||||
|
||||
func (s Creator) Validate(ctx context.Context, entity *resultprocessor.Create) error {
|
||||
func (s *Creator) Validate(ctx context.Context, entity *resultprocessor.Create) error {
|
||||
// TODO
|
||||
// Type, RequiredQueryIDs, Config
|
||||
return nil
|
||||
|
||||
@@ -2,10 +2,10 @@ package contextfull_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
contextfull "queryorchestration/internal/query/types/contextFull"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -19,13 +19,11 @@ func TestCreatorValidate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := contextfull.NewCreator(db)
|
||||
svc := contextfull.NewCreator()
|
||||
assert.NotNil(t, svc)
|
||||
|
||||
entity := &resultprocessor.Create{
|
||||
|
||||
@@ -8,11 +8,11 @@ type Result struct {
|
||||
value string
|
||||
}
|
||||
|
||||
func NewResult(value string) Result {
|
||||
return Result{value}
|
||||
func NewResult(value string) *Result {
|
||||
return &Result{value}
|
||||
}
|
||||
|
||||
func (r Result) GetValue(ctx context.Context) (string, error) {
|
||||
func (r *Result) GetValue(ctx context.Context) (string, error) {
|
||||
// TODO - get value from s3
|
||||
return r.value, nil
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
type Extractor struct {
|
||||
}
|
||||
|
||||
func NewExtractor() Extractor {
|
||||
return Extractor{}
|
||||
func NewExtractor() *Extractor {
|
||||
return &Extractor{}
|
||||
}
|
||||
|
||||
func (e Extractor) Process(ctx context.Context, query *resultprocessor.Query, values *[]resultprocessor.Value) (string, error) {
|
||||
func (e *Extractor) Process(ctx context.Context, query *resultprocessor.Query, values *[]resultprocessor.Value) (string, error) {
|
||||
if values != nil && len(*values) > 0 {
|
||||
return "", errors.New("no requirements expected")
|
||||
}
|
||||
|
||||
@@ -2,19 +2,16 @@ package contextfull
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
)
|
||||
|
||||
type Updator struct {
|
||||
db *database.Connection
|
||||
type Updator struct{}
|
||||
|
||||
func NewUpdator() *Updator {
|
||||
return &Updator{}
|
||||
}
|
||||
|
||||
func NewUpdator(db *database.Connection) Updator {
|
||||
return Updator{db}
|
||||
}
|
||||
|
||||
func (s Updator) Validate(ctx context.Context, current *resultprocessor.Query, entity *resultprocessor.Update) error {
|
||||
func (s *Updator) Validate(ctx context.Context, current *resultprocessor.Query, entity *resultprocessor.Update) error {
|
||||
// TODO
|
||||
// Type, RequiredQueryIDs, Config
|
||||
return nil
|
||||
|
||||
@@ -2,10 +2,10 @@ package contextfull_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
contextfull "queryorchestration/internal/query/types/contextFull"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,13 +20,11 @@ func TestUpdatorValidate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := contextfull.NewUpdator(db)
|
||||
svc := contextfull.NewUpdator()
|
||||
assert.NotNil(t, svc)
|
||||
|
||||
current := &resultprocessor.Query{
|
||||
|
||||
@@ -2,19 +2,16 @@ package jsonextractor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
)
|
||||
|
||||
type Creator struct {
|
||||
db *database.Connection
|
||||
type Creator struct{}
|
||||
|
||||
func NewCreator() *Creator {
|
||||
return &Creator{}
|
||||
}
|
||||
|
||||
func NewCreator(db *database.Connection) Creator {
|
||||
return Creator{db}
|
||||
}
|
||||
|
||||
func (s Creator) Validate(ctx context.Context, entity *resultprocessor.Create) error {
|
||||
func (s *Creator) Validate(ctx context.Context, entity *resultprocessor.Create) error {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package jsonextractor_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -19,13 +19,11 @@ func TestCreatorValidate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := jsonextractor.NewCreator(db)
|
||||
svc := jsonextractor.NewCreator()
|
||||
assert.NotNil(t, svc)
|
||||
|
||||
entity := &resultprocessor.Create{
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
contextfull "queryorchestration/internal/query/types/contextFull"
|
||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -23,13 +24,11 @@ func TestJSONProcess(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
extractor := jsonextractor.NewExtractor(db)
|
||||
extractor := jsonextractor.NewExtractor(cfg)
|
||||
|
||||
query := &resultprocessor.Query{
|
||||
ID: uuid.New(),
|
||||
@@ -93,13 +92,11 @@ func TestJSONProcessJSON(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
extractor := jsonextractor.NewExtractor(db)
|
||||
extractor := jsonextractor.NewExtractor(cfg)
|
||||
|
||||
query := &resultprocessor.Query{
|
||||
ID: uuid.New(),
|
||||
@@ -178,13 +175,11 @@ func TestJSONProcessResults(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
extractor := jsonextractor.NewExtractor(db)
|
||||
extractor := jsonextractor.NewExtractor(cfg)
|
||||
|
||||
query := &resultprocessor.Query{
|
||||
ID: uuid.New(),
|
||||
|
||||
@@ -8,11 +8,11 @@ type Result struct {
|
||||
value string
|
||||
}
|
||||
|
||||
func NewResult(value string) Result {
|
||||
return Result{value}
|
||||
func NewResult(value string) *Result {
|
||||
return &Result{value}
|
||||
}
|
||||
|
||||
func (r Result) GetValue(ctx context.Context) (string, error) {
|
||||
func (r *Result) GetValue(ctx context.Context) (string, error) {
|
||||
return r.value, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,23 +7,24 @@ import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type Extractor struct {
|
||||
db *database.Connection
|
||||
cfg serviceconfig.ConfigProvider
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
func NewExtractor(db *database.Connection) Extractor {
|
||||
return Extractor{db}
|
||||
func NewExtractor(cfg serviceconfig.ConfigProvider) *Extractor {
|
||||
return &Extractor{cfg}
|
||||
}
|
||||
|
||||
func (e Extractor) Process(ctx context.Context, query *resultprocessor.Query, values *[]resultprocessor.Value) (string, error) {
|
||||
func (e *Extractor) Process(ctx context.Context, query *resultprocessor.Query, values *[]resultprocessor.Value) (string, error) {
|
||||
if values == nil || len(*values) != 1 {
|
||||
return "", fmt.Errorf("JSON Extraction requires 1 result")
|
||||
}
|
||||
@@ -33,7 +34,7 @@ func (e Extractor) Process(ctx context.Context, query *resultprocessor.Query, va
|
||||
return "", err
|
||||
}
|
||||
|
||||
byteConfig, err := e.db.Queries.GetQueryConfig(ctx, &repository.GetQueryConfigParams{
|
||||
byteConfig, err := e.cfg.GetDBQueries().GetQueryConfig(ctx, &repository.GetQueryConfigParams{
|
||||
Queryid: database.MustToDBUUID(query.ID),
|
||||
Addedversion: query.Version,
|
||||
})
|
||||
|
||||
@@ -2,19 +2,17 @@ package jsonextractor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
)
|
||||
|
||||
type Updator struct {
|
||||
db *database.Connection
|
||||
}
|
||||
|
||||
func NewUpdator(db *database.Connection) Updator {
|
||||
return Updator{db}
|
||||
func NewUpdator() *Updator {
|
||||
return &Updator{}
|
||||
}
|
||||
|
||||
func (s Updator) Validate(ctx context.Context, current *resultprocessor.Query, entity *resultprocessor.Update) error {
|
||||
func (s *Updator) Validate(ctx context.Context, current *resultprocessor.Query, entity *resultprocessor.Update) error {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package jsonextractor_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,13 +20,11 @@ func TestUpdatorValidate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := jsonextractor.NewUpdator(db)
|
||||
svc := jsonextractor.NewUpdator()
|
||||
assert.NotNil(t, svc)
|
||||
|
||||
current := &resultprocessor.Query{
|
||||
|
||||
+55
-63
@@ -44,7 +44,7 @@ func (s *Service) normalizeUpdate(ctx context.Context, current *Query, entity *r
|
||||
}
|
||||
|
||||
if entity.RequiredQueryIDs != nil {
|
||||
createsloop, err := s.db.Queries.IsQueryInDependencyTree(ctx, &repository.IsQueryInDependencyTreeParams{
|
||||
createsloop, err := s.cfg.GetDBQueries().IsQueryInDependencyTree(ctx, &repository.IsQueryInDependencyTreeParams{
|
||||
Requiredqueryid: database.MustToDBUUID(current.ID),
|
||||
ID: database.MustToDBUUIDArray(*entity.RequiredQueryIDs),
|
||||
})
|
||||
@@ -80,81 +80,73 @@ func (s *Service) normalizeUpdate(ctx context.Context, current *Query, entity *r
|
||||
}
|
||||
|
||||
func (s *Service) submitUpdate(ctx context.Context, current *Query, entity *resultprocessor.Update) error {
|
||||
tx, err := s.db.Pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = tx.Rollback(ctx)
|
||||
}()
|
||||
err := s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
|
||||
latestVersion := current.LatestVersion + 1
|
||||
id := database.MustToDBUUID(entity.ID)
|
||||
|
||||
qtx := s.db.Queries.WithTx(tx)
|
||||
|
||||
latestVersion := current.LatestVersion + 1
|
||||
id := database.MustToDBUUID(entity.ID)
|
||||
|
||||
addIDs := getSetDifference(entity.RequiredQueryIDs, current.RequiredQueryIDs)
|
||||
for _, qID := range addIDs {
|
||||
err = qtx.AddRequiredQuery(ctx, &repository.AddRequiredQueryParams{
|
||||
Queryid: id,
|
||||
Requiredqueryid: database.MustToDBUUID(qID),
|
||||
Addedversion: latestVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
addIDs := getSetDifference(entity.RequiredQueryIDs, current.RequiredQueryIDs)
|
||||
for _, qID := range addIDs {
|
||||
err := q.AddRequiredQuery(ctx, &repository.AddRequiredQueryParams{
|
||||
Queryid: id,
|
||||
Requiredqueryid: database.MustToDBUUID(qID),
|
||||
Addedversion: latestVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removeIDs := getSetDifference(current.RequiredQueryIDs, entity.RequiredQueryIDs)
|
||||
for _, qID := range removeIDs {
|
||||
err = qtx.RemoveRequiredQuery(ctx, &repository.RemoveRequiredQueryParams{
|
||||
Queryid: id,
|
||||
Requiredqueryid: database.MustToDBUUID(qID),
|
||||
Removedversion: &latestVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
removeIDs := getSetDifference(current.RequiredQueryIDs, entity.RequiredQueryIDs)
|
||||
for _, qID := range removeIDs {
|
||||
err := q.RemoveRequiredQuery(ctx, &repository.RemoveRequiredQueryParams{
|
||||
Queryid: id,
|
||||
Requiredqueryid: database.MustToDBUUID(qID),
|
||||
Removedversion: &latestVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if entity.Config != nil && *entity.Config != "" {
|
||||
err = qtx.RemoveQueryConfig(ctx, &repository.RemoveQueryConfigParams{
|
||||
Queryid: id,
|
||||
Removedversion: &latestVersion,
|
||||
if entity.Config != nil && *entity.Config != "" {
|
||||
err := q.RemoveQueryConfig(ctx, &repository.RemoveQueryConfigParams{
|
||||
Queryid: id,
|
||||
Removedversion: &latestVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = q.AddQueryConfig(ctx, &repository.AddQueryConfigParams{
|
||||
Queryid: id,
|
||||
Config: []byte(*entity.Config),
|
||||
Addedversion: latestVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
activeVersion := entity.ActiveVersion
|
||||
if activeVersion == nil {
|
||||
activeVersion = ¤t.ActiveVersion
|
||||
}
|
||||
|
||||
err := q.UpdateQuery(ctx, &repository.UpdateQueryParams{
|
||||
Latestversion: latestVersion,
|
||||
Activeversion: *activeVersion,
|
||||
ID: id,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = qtx.AddQueryConfig(ctx, &repository.AddQueryConfigParams{
|
||||
Queryid: id,
|
||||
Config: []byte(*entity.Config),
|
||||
Addedversion: latestVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
activeVersion := entity.ActiveVersion
|
||||
if activeVersion == nil {
|
||||
activeVersion = ¤t.ActiveVersion
|
||||
}
|
||||
|
||||
err = qtx.UpdateQuery(ctx, &repository.UpdateQueryParams{
|
||||
Latestversion: latestVersion,
|
||||
Activeversion: *activeVersion,
|
||||
ID: id,
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Commit(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -185,9 +177,9 @@ func getSetDifference(setA *[]uuid.UUID, setB *[]uuid.UUID) []uuid.UUID {
|
||||
func (s *Service) getUpdator(qType resultprocessor.Type) (resultprocessor.Updator, error) {
|
||||
switch qType {
|
||||
case resultprocessor.TypeJsonExtractor:
|
||||
return jsonextractor.NewUpdator(s.db), nil
|
||||
return jsonextractor.NewUpdator(), nil
|
||||
case resultprocessor.TypeContextFull:
|
||||
return contextfull.NewUpdator(s.db), nil
|
||||
return contextfull.NewUpdator(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("attempting to process invalid query type")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -21,12 +22,10 @@ func TestUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
svc := query.New(db, &query.Services{})
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
svc := query.New(cfg, &query.Services{})
|
||||
|
||||
config := "{\"path\":\"example_path\"}"
|
||||
existing := query.Query{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user