github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/syz-cluster/pkg/db/base_finding_repo.go (about)

     1  // Copyright 2025 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  package db
     5  
     6  import (
     7  	"context"
     8  
     9  	"cloud.google.com/go/spanner"
    10  )
    11  
    12  type BaseFindingRepository struct {
    13  	client *spanner.Client
    14  }
    15  
    16  func NewBaseFindingRepository(client *spanner.Client) *BaseFindingRepository {
    17  	return &BaseFindingRepository{
    18  		client: client,
    19  	}
    20  }
    21  
    22  func (repo *BaseFindingRepository) Save(ctx context.Context, info *BaseFinding) error {
    23  	_, err := repo.client.ReadWriteTransaction(ctx,
    24  		func(ctx context.Context, txn *spanner.ReadWriteTransaction) error {
    25  			m, err := spanner.InsertOrUpdateStruct("BaseFindings", info)
    26  			if err != nil {
    27  				return err
    28  			}
    29  			return txn.BufferWrite([]*spanner.Mutation{m})
    30  		})
    31  	return err
    32  }
    33  
    34  func (repo *BaseFindingRepository) Exists(ctx context.Context, info *BaseFinding) (bool, error) {
    35  	entity, err := readEntity[BaseFinding](ctx, repo.client.Single(), spanner.Statement{
    36  		SQL: `SELECT * FROM BaseFindings WHERE
    37  CommitHash = @commit AND
    38  Config = @config AND
    39  Arch = @arch AND
    40  Title = @title`,
    41  		Params: map[string]interface{}{
    42  			"commit": info.CommitHash,
    43  			"config": info.Config,
    44  			"arch":   info.Arch,
    45  			"title":  info.Title,
    46  		},
    47  	})
    48  	return entity != nil, err
    49  }