variable

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: 17 Imported by: 0

Documentation

Overview

Package object implements the database.Model interface for the Variable 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, vv ...*Variable) error

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

func Model

func Model(vv []*Variable) func(int) database.Model

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

Types

type Event added in v1.1.0

type Event struct {
	Variable *Variable
	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

	Variables *Store `schema:"-"`
	Key       string `schema:"key"   json:"key"`
	Value     string `schema:"value" json:"value"`
}

Form is the type that represents input data for creating a new variable.

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, Key, and Value 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 Key field is then checked, followed by a validitity check for that Key (is only letters, and numbers with dashes). A uniqueness check is done on the Name for the current Namespace. Another check is also done to check the presence of the Value field.

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 Variable 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 Variable 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
}

Store is the type for creating and modifying Variable models in the database.

func NewStore

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

NewStore returns a new Store for querying the variables table. Each of the given models is bound to the returned Store.

func (*Store) All

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

All returns a slice of Variable 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, key, val string) (*Variable, error)

Create creates a new Variable model with the given key and value.

func (*Store) Delete

func (s *Store) Delete(ids ...int64) error

Delete deletes the Variable models from the database with the given ids.

func (*Store) Get

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

All returns a single Variable model, 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) ([]*Variable, database.Paginator, error)

Index returns the paginated results from the variables table depending on the values that are present in url.Values. Detailed below are the values that are used from the given url.Values,

key - This applies the database.Search query.Option using the value of key

func (*Store) Load

func (s *Store) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Variable 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() *Variable

New returns a new Variable 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 variables 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.

type Variable

type Variable struct {
	ID          int64         `db:"id"`
	UserID      int64         `db:"user_id"`
	AuthorID    int64         `db:"author_id"`
	NamespaceID sql.NullInt64 `db:"namespace_id"`
	Key         string        `db:"key"`
	Value       string        `db:"value"`
	CreatedAt   time.Time     `db:"created_at"`

	Author    *user.User           `db:"-"`
	User      *user.User           `db:"-"`
	Namespace *namespace.Namespace `db:"-"`
}

Variable is the type that represents a variable that has been set by a user.

func FromContext

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

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

func (*Variable) Bind

func (v *Variable) 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 (*Variable) Endpoint

func (v *Variable) Endpoint(uri ...string) string

Endpoint returns the endpoint to the current Variable database, with the given URI parts appended to it.

func (*Variable) IsZero

func (v *Variable) IsZero() bool

IsZero implements the database.Model interface.

func (*Variable) JSON

func (v *Variable) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Variable values under each key. If any of the User, or Namespace bound models exist on the Variable, then the JSON representation of these models will be returned in the map, under the user, and namespace keys respectively.

func (*Variable) Primary

func (v *Variable) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Variable) SetPrimary

func (v *Variable) SetPrimary(i int64)

SetPrimary implements the database.Model interface.

func (*Variable) Values

func (v *Variable) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, user_id, namespace_id, key, and value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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