-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,541 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package db | ||
|
||
import "errors" | ||
|
||
type readerRWAdapter struct{ DBReader } | ||
|
||
var ( | ||
// ErrReadOnly is returned when a write operation is attempted on a read-only transaction. | ||
ErrReadOnly = errors.New("Cannot modify read-only transaction") | ||
) | ||
|
||
// Returns a ReadWriter that forwards to a reader and errors if writes are | ||
// attempted. Can be used to pass a Reader when a ReadWriter is expected | ||
// but no writes will actually occur. | ||
func NewReadWriterFromReader(r DBReader) DBReadWriter { | ||
return readerRWAdapter{r} | ||
} | ||
|
||
func (readerRWAdapter) Set([]byte, []byte) error { | ||
return ErrReadOnly | ||
} | ||
|
||
func (readerRWAdapter) Delete([]byte) error { | ||
return ErrReadOnly | ||
} | ||
|
||
func (rw readerRWAdapter) Commit() error { | ||
rw.Discard() | ||
return nil | ||
} |
Oops, something went wrong.