Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit d968328

Browse files
committed
HydrolixBackendConnector Exec
1 parent af2c054 commit d968328

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

platform/backend_connectors/hydrolix_backend_connector.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
package backend_connectors
55

66
import (
7+
"bytes"
78
"context"
89
"database/sql"
10+
"fmt"
911
"github.com/QuesmaOrg/quesma/platform/config"
12+
"github.com/QuesmaOrg/quesma/platform/logger"
13+
"io"
14+
"net/http"
1015

1116
quesma_api "github.com/QuesmaOrg/quesma/platform/v2/core"
1217
)
1318

1419
type HydrolixBackendConnector struct {
1520
BasicSqlBackendConnector
16-
cfg *config.RelationalDbConfiguration
21+
cfg *config.RelationalDbConfiguration
22+
IngestURL string
23+
AccessToken string
1724
}
1825

1926
func (p *HydrolixBackendConnector) GetId() quesma_api.BackendConnectorType {
@@ -48,10 +55,35 @@ func (p *HydrolixBackendConnector) InstanceName() string {
4855
}
4956

5057
func (p *HydrolixBackendConnector) Exec(ctx context.Context, query string, args ...interface{}) error {
51-
if len(args) == 0 {
58+
if p.IngestURL == "" || p.AccessToken == "" {
59+
logger.Info().Msg("missing ingest URL or access token")
60+
// TODO for fallback, execute the query directly on the database connection
5261
_, err := p.connection.ExecContext(ctx, query)
5362
return err
5463
}
55-
_, err := p.connection.ExecContext(ctx, query, args...)
56-
return err
64+
65+
// Create HTTP request using the JSON payload from query
66+
req, err := http.NewRequestWithContext(ctx, "POST", p.IngestURL, bytes.NewBufferString(query))
67+
if err != nil {
68+
return fmt.Errorf("failed to create request: %w", err)
69+
}
70+
req.Header.Set("Authorization", "Bearer "+p.AccessToken)
71+
req.Header.Set("Content-Type", "application/json")
72+
73+
// Execute HTTP request
74+
client := &http.Client{}
75+
resp, err := client.Do(req)
76+
if err != nil {
77+
return fmt.Errorf("request failed: %w", err)
78+
}
79+
defer resp.Body.Close()
80+
81+
// Handle error response
82+
if resp.StatusCode >= 400 {
83+
body, _ := io.ReadAll(resp.Body)
84+
return fmt.Errorf("ingest failed: %s — %s", resp.Status, string(body))
85+
}
86+
87+
fmt.Printf("Ingest successful: %s\n", resp.Status)
88+
return nil
5789
}

0 commit comments

Comments
 (0)