Skip to content

Commit

Permalink
fixup! feat(db): Add Epoch and Snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Aug 9, 2024
1 parent f277774 commit 54e758a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions internal/repository/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (pg *Database) InsertReport(
func (pg *Database) InsertSnapshot(
ctx context.Context,
snapshot *Snapshot,
) error {
) (id uint64, _ error) {
query := `
INSERT INTO snapshot
(input_id,
Expand All @@ -277,20 +277,21 @@ func (pg *Database) InsertSnapshot(
VALUES
(@inputId,
@appAddress,
@uri)`
@uri)
RETURNING id`

args := pgx.NamedArgs{
"inputId": snapshot.InputId,
"appAddress": snapshot.AppAddress,
"uri": snapshot.URI,
}

_, err := pg.db.Exec(ctx, query, args)
err := pg.db.QueryRow(ctx, query, args).Scan(&id)
if err != nil {
return fmt.Errorf("%w: %w", ErrInsertRow, err)
return 0, fmt.Errorf("%w: %w", ErrInsertRow, err)
}

return nil
return id, nil
}

func (pg *Database) GetNodeConfig(
Expand Down
3 changes: 2 additions & 1 deletion internal/repository/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ func (s *RepositorySuite) SetupDatabase() {
URI: "/some/path",
}

err = s.database.InsertSnapshot(s.ctx, &snapshot)
id, err := s.database.InsertSnapshot(s.ctx, &snapshot)
s.Require().Nil(err)
s.Require().Equal(uint64(1), id)
}

func (s *RepositorySuite) TestApplicationExists() {
Expand Down

0 comments on commit 54e758a

Please sign in to comment.