Skip to content

Commit

Permalink
fix(maestro): fix sqls (#2675)
Browse files Browse the repository at this point in the history
* fix(maestro): fix maestro

* fix(maestro): fix SQL.

* fix(maestro): fix SQL.

* fix(maestro): fix SQL.

---------

Co-authored-by: Luiz Pegoraro <[email protected]>
  • Loading branch information
lpegoraro and Luiz Pegoraro authored Oct 2, 2023
1 parent d5316d8 commit 6ca8375
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions maestro/deployment/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ type repositoryService struct {
func (r *repositoryService) FetchAll(ctx context.Context) ([]Deployment, error) {
tx := r.db.MustBeginTx(ctx, nil)
var deployments []Deployment
err := tx.SelectContext(ctx, &deployments, "SELECT * FROM deployments", nil)
query := `
SELECT id,
owner_id,
sink_id,
backend,
config,
last_status,
last_status_update,
last_error_message,
last_error_time,
collector_name,
last_collector_deploy_time,
last_collector_stop_time
FROM deployments`
err := tx.SelectContext(ctx, &deployments, query, nil)
if err != nil {
_ = tx.Rollback()
return nil, err
Expand Down Expand Up @@ -135,8 +149,23 @@ func (r *repositoryService) Remove(ctx context.Context, ownerId string, sinkId s
func (r *repositoryService) FindByOwnerAndSink(ctx context.Context, ownerId string, sinkId string) (*Deployment, error) {
tx := r.db.MustBeginTx(ctx, nil)
var rows []Deployment
err := tx.SelectContext(ctx, &rows, "SELECT * FROM deployments WHERE owner_id = :owner_id AND sink_id = :sink_id",
map[string]interface{}{"owner_id": ownerId, "sink_id": sinkId})
args := []interface{}{ownerId, sinkId}
query := `
SELECT id,
owner_id,
sink_id,
backend,
config,
last_status,
last_status_update,
last_error_message,
last_error_time,
collector_name,
last_collector_deploy_time,
last_collector_stop_time
FROM deployments WHERE owner_id = ? AND sink_id = ?
`
err := tx.SelectContext(ctx, &rows, query, args)
if err != nil {
_ = tx.Rollback()
return nil, err
Expand Down

0 comments on commit 6ca8375

Please sign in to comment.