func (d *DBBackedStore) PutSD(hash string, blob stream.Blob) error {
	var blobContents db.SdBlob
	err := json.Unmarshal(blob, &blobContents)
	if err != nil {
		return errors.Err(err)
	}
	if blobContents.StreamHash == "" {
		return errors.Err("sd blob is missing stream hash")
	}
	err = d.blobs.PutSD(hash, blob)
	if err != nil {
		return err
	}
	return d.db.AddSDBlob(hash, len(blob), blobContents)
}
PutSD stores the SDBlob in the S3 store. It will return an error if the sd blob is missing the stream hash or if
there is an error storing the blob information in the DB.
package store
import (
	"encoding/json"
	"sync"
	"time"
	"github.com/lbryio/reflector.go/db"
	"github.com/lbryio/reflector.go/shared"
	"github.com/lbryio/lbry.go/v2/extras/errors"
	"github.com/lbryio/lbry.go/v2/stream"
	log "github.com/sirupsen/logrus"
)
type DBBackedStore struct {
	blobs        BlobStore
	db           *db.SQL
	blockedMu    sync.RWMutex
	blocked      map[string]bool
	deleteOnMiss bool
}
func NewDBBackedStore(blobs BlobStore, db *db.SQL, deleteOnMiss bool) *DBBackedStore {
	return &DBBackedStore{blobs: blobs, db: db, deleteOnMiss: deleteOnMiss}
}
const nameDBBacked = "db-backed"
func (d *DBBackedStore) Name() string { return nameDBBacked }
func (d *DBBackedStore) Has(hash string) (bool, error) {
	return d.db.HasBlob(hash, false)
}
func (d *DBBackedStore) Get(hash string) (stream.Blob, shared.BlobTrace, error) {
	start := time.Now()
	has, err := d.db.HasBlob(hash, true)
	if err != nil {
		return nil, shared.NewBlobTrace(time.Since(start), d.Name()), err
	}
	if !has {
		return nil, shared.NewBlobTrace(time.Since(start), d.Name()), ErrBlobNotFound
	}
	b, stack, err := d.blobs.Get(hash)
	if d.deleteOnMiss && errors.Is(err, ErrBlobNotFound) {
		e2 := d.Delete(hash)
		if e2 != nil {
			log.Errorf("error while deleting blob from db: %s", errors.FullTrace(err))
		}
	}
	return b, stack.Stack(time.Since(start), d.Name()), err
}
func (d *DBBackedStore) Put(hash string, blob stream.Blob) error {
	err := d.blobs.Put(hash, blob)
	if err != nil {
		return err
	}
	return d.db.AddBlob(hash, len(blob), true)
}