object

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package object implements the database.Model interface for the Object entity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitEvent added in v1.1.0

func InitEvent(dis event.Dispatcher) queue.InitFunc

func LoadRelations

func LoadRelations(loaders *database.Loaders, oo ...*Object) error

LoadRelations loads all of the available relations for the given Object models using the given loaders available.

func Model

func Model(oo []*Object) func(int) database.Model

Model is called along with database.ModelSlice to convert the given slice of Object models to a slice of database.Model interfaces.

Types

type Event added in v1.1.0

type Event struct {
	Object *Object
	Action string
	// contains filtered or unexported fields
}

func (*Event) Name added in v1.1.0

func (ev *Event) Name() string

func (*Event) Perform added in v1.1.0

func (ev *Event) Perform() error

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

func (f Form) Fields() map[string]string

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

func (f *Form) Validate() error

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

func FromContext(ctx context.Context) (*Object, bool)

FromContext returns the Object model from the given context, if any.

func (*Object) Bind

func (o *Object) Bind(mm ...database.Model)

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

func (o *Object) Endpoint(uri ...string) string

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) IsZero

func (o *Object) IsZero() bool

IsZero implements the database.Model interface.

func (*Object) JSON

func (o *Object) JSON(addr string) map[string]interface{}

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) Primary

func (o *Object) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Object) SetPrimary

func (o *Object) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (*Object) Values

func (o *Object) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, user_id, namespace_id, hash, name, type, size, md5, sha256, and deleted_at.

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

func NewStore(db *sqlx.DB, mm ...database.Model) *Store

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

func NewStoreWithBlockStore(db *sqlx.DB, blockStore fs.Store, mm ...database.Model) *Store

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

func (s *Store) All(opts ...query.Option) ([]*Object, error)

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

func (s *Store) Bind(mm ...database.Model)

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) Chown

func (s *Store) Chown(from, to int64) error

func (*Store) Create

func (s *Store) Create(authorId int64, name, hash string, rs io.ReadSeeker) (*Object, error)

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

func (s *Store) Delete(id int64, hash string) error

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

func (s *Store) Get(opts ...query.Option) (*Object, error)

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

func (s *Store) Index(vals url.Values, opts ...query.Option) ([]*Object, database.Paginator, error)

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

func (s *Store) New() *Object

New returns a new Object binding any non-nil models to it from the current Store.

func (*Store) Paginate

func (s *Store) Paginate(page int64, opts ...query.Option) (database.Paginator, error)

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.

func (*Store) SetBlockStore added in v1.1.0

func (s *Store) SetBlockStore(store fs.Store)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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