Documentation ¶
Overview ¶
Package object implements the database.Model interface for the Object entity.
Index ¶
- func InitEvent(dis event.Dispatcher) queue.InitFunc
- func LoadRelations(loaders *database.Loaders, oo ...*Object) error
- func Model(oo []*Object) func(int) database.Model
- type Event
- type Form
- type Object
- func (o *Object) Bind(mm ...database.Model)
- func (o *Object) Endpoint(uri ...string) string
- func (o *Object) IsZero() bool
- func (o *Object) JSON(addr string) map[string]interface{}
- func (o *Object) Primary() (string, int64)
- func (o *Object) SetPrimary(id int64)
- func (o *Object) Values() map[string]interface{}
- type Store
- func (s *Store) All(opts ...query.Option) ([]*Object, error)
- func (s *Store) Bind(mm ...database.Model)
- func (s *Store) Chown(from, to int64) error
- func (s *Store) Create(authorId int64, name, hash string, rs io.ReadSeeker) (*Object, error)
- func (s *Store) Delete(id int64, hash string) error
- func (s *Store) Get(opts ...query.Option) (*Object, error)
- func (s *Store) Index(vals url.Values, opts ...query.Option) ([]*Object, database.Paginator, error)
- func (s *Store) Load(key string, vals []interface{}, load database.LoaderFunc) error
- func (s *Store) New() *Object
- func (s *Store) Paginate(page int64, opts ...query.Option) (database.Paginator, error)
- func (s *Store) SetBlockStore(store fs.Store)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadRelations ¶
LoadRelations loads all of the available relations for the given Object models using the given loaders available.
Types ¶
type Form ¶
type Form struct { namespace.Resource *webutil.File Objects *Store `schema:"-"` Name string `schema:"name"` }
Form is the type that represents input data for uploading a new object.
func (Form) Fields ¶
Fields returns a map of fields for the current Form. This map will contain the Namespace, and Name fields of the current Form.
func (*Form) Validate ¶
Validate will bind a Namespace to the Form's Store, if the Namespace field is present. The presence of the Name field is then checked, followed by a validity check for that Name (is only letters, numbers, dashes, and dots). A uniqueness check on the Name is then done for the current Namespace.
type Object ¶
type Object struct { ID int64 `db:"id"` UserID int64 `db:"user_id"` AuthorID int64 `db:"author_id"` NamespaceID sql.NullInt64 `db:"namespace_id"` Hash string `db:"hash"` Name string `db:"name"` Type string `db:"type"` Size int64 `db:"size"` MD5 []byte `db:"md5"` SHA256 []byte `db:"sha256"` CreatedAt time.Time `db:"created_at"` DeletedAt sql.NullTime `db:"deleted_at"` Author *user.User `db:"-"` User *user.User `db:"-"` Namespace *namespace.Namespace `db:"-"` }
Object is the type that represents an object that has been uploaded by a user.
func FromContext ¶
FromContext returns the Object model from the given context, if any.
func (*Object) Bind ¶
Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User or namespace.Namespace.
func (*Object) Endpoint ¶
Endpoint returns the endpoint for the current Object. Each URI part in the given variadic list will be appended to the final returned string.
func (*Object) JSON ¶
JSON implements the database.Model interface. This will return a map with the current Object values under each key. If any of the User, or Namespace bound models exist on the Object, then the JSON representation of these models will be returned in the map, under the user, and namespace keys respectively.
func (*Object) SetPrimary ¶
SetPrimary implements the database.Model interface.
type Store ¶
type Store struct { database.Store // User is the bound user.User model. If not nil this will bind the // user.User model to any Object models that are created. If not nil this // will append a WHERE clause on the user_id column for all SELECT queries // performed. User *user.User // Namespace is the bound namespace.Namespace model. If not nil this will // bind the namespace.Namespace model to any Object models that are created. // If not nil this will append a WHERE clause on the namespace_id column for // all SELECT queries performed. Namespace *namespace.Namespace // contains filtered or unexported fields }
Store is the type for creating and modifying Object models in the database. The Store type can have an underlying fs.Store implementation that is used for storing the contents of an object.
func NewStore ¶
NewStore returns a new Store for querying the objects table. Each database passed to this function will be bound to the returned Store.
func NewStoreWithBlockStore ¶
NewStoreWithBlockStore is functionally the same as NewStore, however it sets the fs.Store to use on the returned Store. This will allow f or an object file to be stored.
func (*Store) All ¶
All returns a slice of Object models, applying each query.Option that is given. The namespace.WhereCollaborator option is applied to the *user.User bound database, and the database.Where option is applied to the *namespace.Namespace bound database.
func (*Store) Bind ¶
Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User or namespace.Namespace.
func (*Store) Create ¶
Create stores a new object with the given name, and hash. The given io.ReadSeeker is used to determine the content type of the object being stored, and used to copy the contents of the object to the underlying fs.Store. It is expected for the Store to have a fs.Store set on it, otherwise it will error.
func (*Store) Delete ¶
Delete deletes the object from the database of the given id. The given hash is used to remove the object from the underlying fs.Store.
func (*Store) Get ¶
Get returns a single Object database, applying each query.Option that is given. The namespace.WhereCollaborator option is applied to the *user.User bound database, and the database.Where option is applied to the *namespace.Namespace bound database.
func (*Store) Index ¶
Index returns the paginated results from the objects table depending on the values that are present in url.Values. Detailed below are the values that are used from the given url.Values,
name - This applies the database.Search query.Option using the value of name
func (*Store) Load ¶
func (s *Store) Load(key string, vals []interface{}, load database.LoaderFunc) error
Load loads in a slice of Object models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls Store.All under the hood, so any bound models will impact the models being loaded.
func (*Store) New ¶
New returns a new Object binding any non-nil models to it from the current Store.
func (*Store) Paginate ¶
Paginate returns the database.Paginator for the objects table for the given page. This applies the namespace.WhereCollaborator option to the *user.User bound database, and the database.Where option to the *namespace.Namespace bound database.