models

package
v0.0.0-...-281c92d Latest Latest
Warning

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

Go to latest
Published: May 5, 2019 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	AccountTableName = "accounts"
)
View Source
const (
	FieldTableName = "fields"
)
View Source
const (
	ItemTableName = "items"
)
View Source
const (
	ItemTypeTableName = "item_types"
)
View Source
const (
	ProjectTableName = "projects"
)
View Source
const (
	RoleTableName = "roles"
)
View Source
const (
	StringTableName = "strings"
)
View Source
const (
	UserTableName = "users"
)

Variables

View Source
var (
	DefaultAdminRole = Role{
		Name:                  "Admin",
		CanEditProject:        true,
		CanEditSchema:         true,
		CanManageUsers:        true,
		CanManageAccessTokens: true,
		CanPublishContent:     true,
	}
	DefaultEditorRole = Role{
		Name:                  "Editor",
		CanEditProject:        false,
		CanEditSchema:         false,
		CanManageUsers:        false,
		CanManageAccessTokens: false,
		CanPublishContent:     true,
	}
)
View Source
var (
	ReservedKeys = []string{"updatedAt", "isValid"}
)

Functions

func CreateItemValues

func CreateItemValues(db *gorm.DB, item *Item) error

func DeleteItemValues

func DeleteItemValues(db *gorm.DB, item *Item) error

func FindFieldRelationships

func FindFieldRelationships(db *gorm.DB, item *Field) error

func FindItemRelationships

func FindItemRelationships(db *gorm.DB, item *Item) error

func FindItemTypeRelationships

func FindItemTypeRelationships(db *gorm.DB, item *ItemType) error

func Models

func Models() []interface{}

Models returns one of every model the database must create

func ValidateCustomPattern

func ValidateCustomPattern(field *Field, v string) error

func ValidateEnumValues

func ValidateEnumValues(field *Field, v string) error

func ValidateLength

func ValidateLength(field *Field, v string) error

func ValidatePredefinedPattern

func ValidatePredefinedPattern(field *Field, v string) error

func ValidateString

func ValidateString(db *gorm.DB, item *Item, field *Field, v string) error

func ValidateUniqueString

func ValidateUniqueString(db *gorm.DB, field *Field, v string) error

Types

type Account

type Account struct {
	gorm.Model
	Email    string `gorm:"unique_index" valid:"email,required"`
	Password string `valid:"length(8|32),matches(^[a-zA-Z0-9]+$),required"`
}

func (*Account) Validate

func (a *Account) Validate() error

type AccountDS

type AccountDS interface {
	Create(*Account) error
	Authenticate(*Account) error
}

func AccountStore

func AccountStore(db *gorm.DB) AccountDS

type AccountSQL

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

func (*AccountSQL) Authenticate

func (s *AccountSQL) Authenticate(acc *Account) error

func (*AccountSQL) Create

func (s *AccountSQL) Create(acc *Account) error

type Field

type Field struct {
	gorm.Model
	ItemTypeID     uint
	ProjectID      uint
	Label          string `gorm:"primary_key"`
	ApiKey         string `gorm:"primary_key"`
	FieldType      string
	Localized      bool
	Hint           string
	AppearanceType string
	Position       int32

	Required                bool
	Unique                  bool
	LengthMin               *int32
	LengthMax               *int32
	LengthEq                *int32
	FormatCustomPattern     *string
	FormatPredefinedPattern *string
	EnumValues              pq.StringArray `gorm:"type:text[]"`

	ItemType ItemType
}

func (*Field) Validate

func (f *Field) Validate() error

type FieldDS

type FieldDS interface {
	Create(*Field) error
	Update(*Field) error
	GetList(itemTypeID uint, projectID uint) ([]Field, error)
	GetListForProject(projectID uint, filter FilterOptions) ([]Field, error)
	Get(*Field) error
	Delete(*Field) error
}

func FieldStore

func FieldStore(db *gorm.DB) FieldDS

type FieldSQL

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

func (*FieldSQL) Create

func (s *FieldSQL) Create(item *Field) error

func (*FieldSQL) Delete

func (s *FieldSQL) Delete(item *Field) error

func (*FieldSQL) Get

func (s *FieldSQL) Get(item *Field) error

func (*FieldSQL) GetList

func (s *FieldSQL) GetList(itemTypeID uint, projectID uint) ([]Field, error)

func (*FieldSQL) GetListForProject

func (s *FieldSQL) GetListForProject(projectID uint, filter FilterOptions) ([]Field, error)

func (*FieldSQL) Update

func (s *FieldSQL) Update(item *Field) error

type FilterOptions

type FilterOptions struct {
	IDs      []uint
	TargetID uint
	Target   string
}

type Item

type Item struct {
	gorm.Model
	ItemTypeID uint
	ProjectID  uint

	ItemType ItemType

	Attributes map[string]interface{} `sql:"-"`
}

func (*Item) Validate

func (f *Item) Validate() error

type ItemDS

type ItemDS interface {
	Create(*Item) error
	Update(*Item) error
	GetList(projectID uint, filter ItemFilterOptions) (int, []Item, error)
	Get(*Item) error
	Delete(*Item) error
}

func ItemStore

func ItemStore(db *gorm.DB) ItemDS

type ItemFilterOptions

type ItemFilterOptions struct {
	IDs        []int
	ItemTypeID uint
	Offset     int
	Limit      int
	// TODO: - support this
	Query string
}

type ItemSQL

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

func (*ItemSQL) Create

func (s *ItemSQL) Create(item *Item) error

func (*ItemSQL) Delete

func (s *ItemSQL) Delete(item *Item) error

func (*ItemSQL) Get

func (s *ItemSQL) Get(item *Item) error

func (*ItemSQL) GetList

func (s *ItemSQL) GetList(projectID uint, filter ItemFilterOptions) (int, []Item, error)

func (*ItemSQL) Update

func (s *ItemSQL) Update(item *Item) error

type ItemType

type ItemType struct {
	gorm.Model
	ProjectID uint
	Name      string `gorm:"primary_key"`
	ApiKey    string `gorm:"primary_key"`

	Fields []Field
}

func (ItemType) Validate

func (t ItemType) Validate() error

type ItemTypeDS

type ItemTypeDS interface {
	Create(*ItemType) error
	Update(*ItemType) error
	GetList(uint) ([]ItemType, error)
	Get(*ItemType) error
	Duplicate(*ItemType) error
	Delete(*ItemType) error
}

func ItemTypeStore

func ItemTypeStore(db *gorm.DB) ItemTypeDS

type ItemTypeSQL

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

func (*ItemTypeSQL) Create

func (s *ItemTypeSQL) Create(item *ItemType) error

func (*ItemTypeSQL) Delete

func (s *ItemTypeSQL) Delete(item *ItemType) error

func (*ItemTypeSQL) Duplicate

func (s *ItemTypeSQL) Duplicate(item *ItemType) error

func (*ItemTypeSQL) Get

func (s *ItemTypeSQL) Get(item *ItemType) error

func (*ItemTypeSQL) GetList

func (s *ItemTypeSQL) GetList(projectID uint) ([]ItemType, error)

func (*ItemTypeSQL) Update

func (s *ItemTypeSQL) Update(item *ItemType) error

type Project

type Project struct {
	gorm.Model
	AccountID uint
	Name      string
}

func (*Project) Validate

func (p *Project) Validate() error

type ProjectDS

type ProjectDS interface {
	Create(*Project) error
	Update(*Project) error
	Get(*Project) error
	GetList() ([]Project, error)
	Delete(*Project) error
}

func ProjectStore

func ProjectStore(db *gorm.DB) ProjectDS

type ProjectSQL

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

func (*ProjectSQL) Create

func (s *ProjectSQL) Create(project *Project) error

func (*ProjectSQL) Delete

func (s *ProjectSQL) Delete(project *Project) error

func (*ProjectSQL) Get

func (s *ProjectSQL) Get(project *Project) error

func (*ProjectSQL) GetList

func (s *ProjectSQL) GetList() ([]Project, error)

func (*ProjectSQL) Update

func (s *ProjectSQL) Update(project *Project) error

type Role

type Role struct {
	gorm.Model
	ProjectID             uint
	Name                  string
	CanEditProject        bool
	CanEditSchema         bool
	CanManageUsers        bool
	CanManageAccessTokens bool
	CanPublishContent     bool
}

func (*Role) Validate

func (r *Role) Validate() error

type RoleDS

type RoleDS interface {
	Create(*Role) error
	Update(*Role) error
	Get(*Role) error
	GetList(uint) ([]Role, error)
	Delete(*Role) error
}

func RoleStore

func RoleStore(db *gorm.DB) RoleDS

type RoleSQL

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

func (*RoleSQL) Create

func (s *RoleSQL) Create(item *Role) error

func (*RoleSQL) Delete

func (s *RoleSQL) Delete(item *Role) error

func (*RoleSQL) Get

func (s *RoleSQL) Get(item *Role) error

func (*RoleSQL) GetList

func (s *RoleSQL) GetList(projectID uint) ([]Role, error)

func (*RoleSQL) Update

func (s *RoleSQL) Update(item *Role) error

type String

type String struct {
	gorm.Model
	ItemID  uint
	FieldID uint

	Value string
}

func (*String) Validate

func (f *String) Validate() error

type User

type User struct {
	gorm.Model
	ProjectID uint
	RoleID    uint
	Email     string `valid:"email,required"`
	State     string

	Role Role
}

func (*User) Validate

func (u *User) Validate() error

type UserDS

type UserDS interface {
	Create(*User) error
	Update(*User) error
	Get(*User) error
	GetList(uint) ([]User, error)
	Delete(*User) error
}

func UserStore

func UserStore(db *gorm.DB) UserDS

type UserSQL

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

func (*UserSQL) Create

func (s *UserSQL) Create(item *User) error

func (*UserSQL) Delete

func (s *UserSQL) Delete(item *User) error

func (*UserSQL) Get

func (s *UserSQL) Get(item *User) error

func (*UserSQL) GetList

func (s *UserSQL) GetList(projectID uint) ([]User, error)

func (*UserSQL) Update

func (s *UserSQL) Update(item *User) error

type Validator

type Validator interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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