attachments

package
v1.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewTempStore = func() (Store, error) {
	db, delete, err := sqlite.CreateTemp()
	if err != nil {
		return nil, errors.Wrap(err, "unable to make temporary attachment store")
	}
	store, err := NewSQLStore(db)
	return &tempStore{
		store: store,
		close: func() error {
			delete()
			return nil
		},
	}, err
}

NewTempStore creates a Store in a temporary file, and when you Close the store, it deletes that file. It's a variable so it can be overwritten if you import this package. The built-in implementation uses SQLite, but any other implementation will work so long as its Close method removes all traces of this store

Functions

func Copy

func Copy(ctx context.Context, dest Store, src Store) error

Types

type MockStore

type MockStore struct {
	mock.Mock
}

MockStore is an autogenerated mock type for the Store type

func NewMockStore

func NewMockStore(t mockConstructorTestingTNewMockStore) *MockStore

NewMockStore creates a new instance of MockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockStore) Close

func (_m *MockStore) Close() error

Close provides a mock function with given fields:

func (*MockStore) DeleteAttachment

func (_m *MockStore) DeleteAttachment(ctx context.Context, id int64) error

DeleteAttachment provides a mock function with given fields: ctx, id

func (*MockStore) GetAttachment

func (_m *MockStore) GetAttachment(ctx context.Context, id int64) ([]byte, error)

GetAttachment provides a mock function with given fields: ctx, id

func (*MockStore) ListAttachments

func (_m *MockStore) ListAttachments(ctx context.Context) ([]int64, error)

ListAttachments provides a mock function with given fields: ctx

func (*MockStore) SetAttachment

func (_m *MockStore) SetAttachment(ctx context.Context, id int64, blob []byte) error

SetAttachment provides a mock function with given fields: ctx, id, blob

type Store

type Store interface {
	// SetAttachment saves an attachment, so that later on GetAttachment can retrieve it.
	SetAttachment(ctx context.Context, id int64, blob []byte) error
	// GetAttachment retrieves an attachment previously stored by SetAttachment. If the ID was never used with SetAttachment, or was deleted with DeleteAttachment, it returns an error.
	GetAttachment(ctx context.Context, id int64) (blob []byte, err error)
	// ListAttachments gives a list of attachment IDs that have been set and haven't been deleted.
	ListAttachments(ctx context.Context) (ids []int64, err error)
	// DeleteAttachment frees up resources used to store an attachment, and causes GetAttachment to error going forward when asked for the deleted attachment.
	DeleteAttachment(ctx context.Context, id int64) (err error)
	// Close allows for cleaning up
	Close() (err error)
}

Store is a way to store and retrieve binary blobs by IDs.

func Discard

func Discard() Store

Discard never actually sets or deletes attachments. Never able to get attachments either.

func NewSQLStore

func NewSQLStore(dbOrTx sqlite.DBOrTx) (Store, error)

NewSQLStore makes a Store that uses an SQL database to store attachments. You can supply either a *sql.DB or a *sql.Tx for the queries to run under.

func NoReads

func NoReads(store Store) Store

func NoWrites

func NoWrites(store Store) Store

func Unclosable

func Unclosable(store Store) Store

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL