Skip to content

Commit

Permalink
chore: integration keys sqlc (#3293)
Browse files Browse the repository at this point in the history
* integration key sqlc queries

* remove statement preparation

* tidy up queries

* require db/tx
  • Loading branch information
andrewbenington authored and AllenDing committed Sep 27, 2023
1 parent 62fb4b4 commit a4c2aac
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 88 deletions.
5 changes: 1 addition & 4 deletions app/initstores.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ func (app *App) initStores(ctx context.Context) error {
}

if app.IntegrationKeyStore == nil {
app.IntegrationKeyStore, err = integrationkey.NewStore(ctx, app.db)
}
if err != nil {
return errors.Wrap(err, "init integration key store")
app.IntegrationKeyStore = integrationkey.NewStore(ctx, app.db)
}

if app.ScheduleRuleStore == nil {
Expand Down
2 changes: 1 addition & 1 deletion devtools/pgdump-lite/pgd/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion devtools/pgdump-lite/pgd/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion devtools/pgdump-lite/pgd/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 132 additions & 0 deletions gadb/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion graphql2/graphqlapp/integrationkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (m *Mutation) CreateIntegrationKey(ctx context.Context, input graphql2.Crea
Name: input.Name,
Type: integrationkey.Type(input.Type),
}
key, err = m.IntKeyStore.CreateKeyTx(ctx, tx, key)
key, err = m.IntKeyStore.Create(ctx, tx, key)
return err
})
return key, err
Expand Down
2 changes: 1 addition & 1 deletion graphql2/graphqlapp/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (a *Mutation) tryDeleteAll(ctx context.Context, input []assignment.RawTarge
case assignment.TargetTypeEscalationPolicy:
err = errors.Wrap(a.PolicyStore.DeleteManyPoliciesTx(ctx, tx, ids), "delete escalation policies")
case assignment.TargetTypeIntegrationKey:
err = errors.Wrap(a.IntKeyStore.DeleteManyTx(ctx, tx, ids), "delete integration keys")
err = errors.Wrap(a.IntKeyStore.DeleteMany(ctx, tx, ids), "delete integration keys")
case assignment.TargetTypeSchedule:
err = errors.Wrap(a.ScheduleStore.DeleteManyTx(ctx, tx, ids), "delete schedules")
case assignment.TargetTypeCalendarSubscription:
Expand Down
39 changes: 39 additions & 0 deletions integrationkey/queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- name: IntKeyGetServiceID :one
SELECT
service_id
FROM
integration_keys
WHERE
id = $1
AND type = $2;

-- name: IntKeyCreate :exec
INSERT INTO integration_keys(id, name, type, service_id)
VALUES ($1, $2, $3, $4);

-- name: IntKeyFindOne :one
SELECT
id,
name,
type,
service_id
FROM
integration_keys
WHERE
id = $1;

-- name: IntKeyFindByService :many
SELECT
id,
name,
type,
service_id
FROM
integration_keys
WHERE
service_id = $1;

-- name: IntKeyDelete :exec
DELETE FROM integration_keys
WHERE id = ANY (@ids::uuid[]);

Loading

0 comments on commit a4c2aac

Please sign in to comment.