gitlab.com/ignitionrobotics/web/ign-go@v1.0.0-rc4/repository/repository.go (about) 1 package repository 2 3 import "errors" 4 5 var ( 6 // ErrNoFilter represents an error when no filter are provided. 7 ErrNoFilter = errors.New("no filters provided") 8 // ErrNoEntriesUpdated represent an error when no entries were updated in the database 9 // after an Update operation. 10 ErrNoEntriesUpdated = errors.New("no entries were updated") 11 // ErrNoEntriesDeleted represent an error when no entries were deleted in the database 12 // after a Delete operation. 13 ErrNoEntriesDeleted = errors.New("no entries were deleted") 14 ) 15 16 // Repository holds methods to CRUD an entity on a certain persistence layer. 17 type Repository interface { 18 // FirstOrCreate inserts a new entry if the given filters don't find any existing record. 19 // entity: must be a pointer to a Model implementation. Results will be saved in this argument if the record exists. 20 FirstOrCreate(entity Model, filters ...Filter) error 21 // Create inserts a single entry. 22 // entity: The entry to insert. 23 Create(entity Model) (Model, error) 24 // CreateBulk is a bulk operation to create multiple entries with a single operation. 25 // entities: should be a slice of a Model implementation. 26 CreateBulk(entities []Model) ([]Model, error) 27 // Find filters entries and stores filtered entries in output. 28 // output: will contain the result of the query. It must be a pointer to a slice. 29 // offset: defines the number of results to skip before loading values to output. 30 // limit: defines the maximum number of entries to write to output. A nil value will write all matching entries. 31 // filters: filter entries by field value. 32 Find(output interface{}, offset, limit *int, filters ...Filter) error 33 // FindOne filters entries and stores the first filtered entry in output. 34 // output: must be a pointer to a Model implementation. 35 FindOne(output Model, filters ...Filter) error 36 // Update updates all model entries that match the provided filters with the given data. 37 // data: must be a map[string]interface{} 38 // filters: selection criteria for entries that should be updated. 39 Update(data interface{}, filters ...Filter) error 40 // Delete removes all the model entries that match filters. 41 // filters: selection criteria for entries that should be deleted. 42 Delete(filters ...Filter) error 43 // Model returns this repository's model. 44 Model() Model 45 }