variable
v1.1.1
Documentation
pkg.go.dev ↗Package object implements the database.Model interface for the Variable entity.
Functions
InitEvent
func InitEvent(dis event.Dispatcher) queue.InitFunc
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.
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
Event
type Event struct {
Variable *Variable
Action string
// contains filtered or unexported fields
}
Event.Name
func (ev *Event) Name() string
Event.Perform
func (ev *Event) Perform() error
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.
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.
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.
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.
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.
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.
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.
Store.Chown
func (s *Store) Chown(from, to int64) error
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.
Store.Delete
func (s *Store) Delete(ids ...int64) error
Delete deletes the Variable models from the database with the given ids.
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.
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
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.
Store.New
func (s *Store) New() *Variable
New returns a new Variable binding any non-nil models to it from the current Store.
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.
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.
FromContext
func FromContext(ctx context.Context) (*Variable, bool)
FromContext returns the Variable model from the given context, if any.
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.
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.
Variable.IsZero
func (v *Variable) IsZero() bool
IsZero implements the database.Model interface.
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.
Variable.Primary
func (v *Variable) Primary() (string, int64)
Primary implements the database.Model interface.
Variable.SetPrimary
func (v *Variable) SetPrimary(i int64)
SetPrimary implements the database.Model interface.
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.