github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/datastore/proxy/readonly.go (about)

     1  package proxy
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/authzed/spicedb/pkg/datastore"
     7  	"github.com/authzed/spicedb/pkg/datastore/options"
     8  )
     9  
    10  var errReadOnly = datastore.NewReadonlyErr()
    11  
    12  type roDatastore struct {
    13  	datastore.Datastore
    14  }
    15  
    16  // NewReadonlyDatastore creates a proxy which disables write operations to a downstream delegate
    17  // datastore.
    18  func NewReadonlyDatastore(delegate datastore.Datastore) datastore.Datastore {
    19  	return roDatastore{Datastore: delegate}
    20  }
    21  
    22  func (rd roDatastore) ReadWriteTx(
    23  	context.Context,
    24  	datastore.TxUserFunc,
    25  	...options.RWTOptionsOption,
    26  ) (datastore.Revision, error) {
    27  	return datastore.NoRevision, errReadOnly
    28  }