aboutsummaryrefslogtreecommitdiffstats
path: root/syz-cluster/pkg/db/base_finding_repo.go
blob: 9ba5df92a55da92561bb3477976fa5b2ead8f602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2025 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package db

import (
	"context"

	"cloud.google.com/go/spanner"
)

type BaseFindingRepository struct {
	client *spanner.Client
}

func NewBaseFindingRepository(client *spanner.Client) *BaseFindingRepository {
	return &BaseFindingRepository{
		client: client,
	}
}

func (repo *BaseFindingRepository) Save(ctx context.Context, info *BaseFinding) error {
	_, err := repo.client.ReadWriteTransaction(ctx,
		func(ctx context.Context, txn *spanner.ReadWriteTransaction) error {
			m, err := spanner.InsertOrUpdateStruct("BaseFindings", info)
			if err != nil {
				return err
			}
			return txn.BufferWrite([]*spanner.Mutation{m})
		})
	return err
}

func (repo *BaseFindingRepository) Exists(ctx context.Context, info *BaseFinding) (bool, error) {
	entity, err := readEntity[BaseFinding](ctx, repo.client.Single(), spanner.Statement{
		SQL: `SELECT * FROM BaseFindings WHERE
CommitHash = @commit AND
Config = @config AND
Arch = @arch AND
Title = @title`,
		Params: map[string]any{
			"commit": info.CommitHash,
			"config": info.Config,
			"arch":   info.Arch,
			"title":  info.Title,
		},
	})
	return entity != nil, err
}