rule

package
v4.1.14 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReplaceGlobals

func ReplaceGlobals(repository Repository) func()

ReplaceGlobals affect a new repository to the global repository singleton

Types

type PostgresRulesRepository

type PostgresRulesRepository struct {
	// contains filtered or unexported fields
}

PostgresRulesRepository is a repository containing the rules based on a PSQL database and implementing the repository interface

func (*PostgresRulesRepository) CheckByName

func (r *PostgresRulesRepository) CheckByName(name string) (bool, error)

CheckByName returns if at least one row exists with the input rule name

func (*PostgresRulesRepository) Create

func (r *PostgresRulesRepository) Create(rule Rule) (int64, error)

Create creates a new Rule in the repository

func (*PostgresRulesRepository) Delete

func (r *PostgresRulesRepository) Delete(id int64) error

Delete deletes an entry from the repository by it's ID

func (*PostgresRulesRepository) Get

func (r *PostgresRulesRepository) Get(id int64) (Rule, bool, error)

Get search and returns an entity from the repository by its id

func (*PostgresRulesRepository) GetAll

func (r *PostgresRulesRepository) GetAll() (map[int64]Rule, error)

GetAll returns all entities in the repository

func (*PostgresRulesRepository) GetAllEnabled

func (r *PostgresRulesRepository) GetAllEnabled() (map[int64]Rule, error)

GetAllEnabled returns all entities in the repository that are enabled (column enabled = true)

func (*PostgresRulesRepository) GetAllModifiedFrom

func (r *PostgresRulesRepository) GetAllModifiedFrom(from time.Time) (map[int64]Rule, error)

GetAllModifiedFrom returns all entities that have been modified since 'from' parameter

func (*PostgresRulesRepository) GetByName

func (r *PostgresRulesRepository) GetByName(name string) (Rule, bool, error)

GetByName search and returns an entity from the repository by its name

func (*PostgresRulesRepository) GetByVersion

func (r *PostgresRulesRepository) GetByVersion(id int64, version int64) (Rule, bool, error)

GetByVersion search and returns an entity from the repository by its id

func (*PostgresRulesRepository) Update

func (r *PostgresRulesRepository) Update(rule Rule) error

Update updates an entity in the repository by its name

type Repository

type Repository interface {
	CheckByName(name string) (bool, error)
	Create(rule Rule) (int64, error)
	Get(id int64) (Rule, bool, error)
	GetByVersion(id int64, version int64) (Rule, bool, error)
	GetByName(name string) (Rule, bool, error)
	Update(rule Rule) error
	Delete(id int64) error
	GetAll() (map[int64]Rule, error)
	GetAllEnabled() (map[int64]Rule, error)
	GetAllModifiedFrom(from time.Time) (map[int64]Rule, error)
}

Repository is a storage interface which can be implemented by multiple backend (in-memory map, sql database, in-memory cache, file system, ...) It allows standard CRUD operation on situations

func NewPostgresRepository

func NewPostgresRepository(dbClient *sqlx.DB) Repository

NewPostgresRepository returns a new instance of PostgresRulesRepository

func R

func R() Repository

R is used to access the global repository singleton

type Rule

type Rule struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Enabled     bool   `json:"enabled"`
	CalendarID  int    `json:"calendarId"`
	ruleeng.DefaultRule
}

Rule ...

func (Rule) EqualTo

func (r Rule) EqualTo(rule Rule) bool

EqualTo returns true if the rule is equal to the rule passed as parameter or false otherwise

func (*Rule) IsValid

func (r *Rule) IsValid() (bool, error)

IsValid checks if a rule definition is valid and has no missing mandatory fields

func (Rule) SameCasesAs

func (r Rule) SameCasesAs(rule Rule) bool

SameCasesAs returns true if the cases of the are equal to the case of the rule passed as parameter or false otherwise

func (*Rule) UnmarshalJSON

func (r *Rule) UnmarshalJSON(data []byte) error

UnmarshalJSON unmashals a quoted json string to Expression

Jump to

Keyboard shortcuts

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