-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sqlc is amazing but because we want to have internal methods like save/update and have a exported method to handle them both we need our own interface and layer for this. We have now made everything use our repository so that use this abstraction across the repository (and have generated mock code to avoid calling the db)
- Loading branch information
1 parent
ef34ad7
commit 1f9c0fa
Showing
18 changed files
with
342 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
slack/slackclient/mock_slackclient linguist-generated | ||
lib/db/mock_db linguist-generated | ||
gen linguist-generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/jackc/pgx/v5/pgconn" | ||
"github.com/rotabot-io/rotabot/lib/zapctx" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type CreateOrUpdateRotaParams struct { | ||
RotaID string | ||
TeamID string | ||
ChannelID string | ||
Name string | ||
Metadata RotaMetadata | ||
} | ||
|
||
func (q *Queries) CreateOrUpdateRota(ctx context.Context, p CreateOrUpdateRotaParams) (string, error) { | ||
l := zapctx.Logger(ctx) | ||
var rotaId string | ||
var err error | ||
if p.RotaID != "" { | ||
rotaId, err = q.updateRota(ctx, updateRotaParams{ | ||
ID: p.RotaID, | ||
Name: p.Name, | ||
Metadata: p.Metadata, | ||
}) | ||
} else { | ||
rotaId, err = q.saveRota(ctx, saveRotaParams{ | ||
Name: p.Name, | ||
TeamID: p.TeamID, | ||
ChannelID: p.ChannelID, | ||
Metadata: p.Metadata, | ||
}) | ||
} | ||
if err != nil { | ||
var pgError *pgconn.PgError | ||
if errors.As(err, &pgError) { | ||
switch pgError.Code { | ||
case "23505": | ||
return "", ErrAlreadyExists | ||
} | ||
} | ||
l.Error("failed to save rota", zap.Error(err)) | ||
return "", err | ||
} | ||
return rotaId, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.