database

package
v0.0.0-...-2448ec3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildValidationErrorMsg

func BuildValidationErrorMsg(errs validator.ValidationErrors) string

func Connect

func Connect() *gorm.DB

func GetDB

func GetDB() *gorm.DB

func Insert

func Insert(m Model) error

func RunMigration

func RunMigration()

Auto Migrate seems to fail to create foreign keys, hence creation of a many to many relation for entries / label failed

https://github.com/jinzhu/gorm/issues/450#issuecomment-487958084

func Update

func Update(m Model) error

Does a full update

Types

type BaseModel

type BaseModel struct {
	ID        uint       `gorm:"primary_key" json:"id"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `sql:"index" json:"-"`
}

type Entry

type Entry struct {
	BaseModel
	PartialEntry
	UserID uint
	Labels []Label `json:"labels" gorm:"many2many:entry_labels;"`
}

The remaining data, generated by the server

func (*Entry) Create

func (entry *Entry) Create() error

func (*Entry) Delete

func (entry *Entry) Delete() error

func (*Entry) Update

func (entry *Entry) Update() error

todo find a way to preload labels here

func (Entry) Validate

func (entry Entry) Validate() error

type Label

type Label struct {
	BaseModel
	PartialLabel
	UserID    uint   `json:"user_id"`
	AvatarUrl string `json:"avatar_url" gorm:"-"`
	HasAvatar bool   `json:"has_avatar"`
}

func (*Label) Create

func (label *Label) Create() error

func (*Label) Delete

func (label *Label) Delete() error

func (*Label) Update

func (label *Label) Update() error

func (Label) Validate

func (label Label) Validate() error

type Model

type Model interface {
	Validate() error
	Update() error
	Create() error
	Delete() error
}

type PartialEntry

type PartialEntry struct {
	Content string `json:"content" gorm:"type:varchar"`
	Title   string `json:"title" gorm:"type:varchar" validate:"required,min=3"`
}

The user modifiable part of Entry

type PartialLabel

type PartialLabel struct {
	Name  string `json:"name" validate:"alphanumunicode,max=100"`
	Color string `json:"color" validate:"hexcolor"`
}

The user modifiable part

type TwoFactorsCookie

type TwoFactorsCookie struct {
	BaseModel
	Uuid      string    `json:"-" validate:"uuid4" gorm:"type:varchar(36)"`
	IpAddr    string    `json:"ip_addr" validate:"ipv4" gorm:"type:varchar(12)"`
	UserAgent string    `json:"user_agent" validate:"max=200" gorm:"type:varchar(200)"`
	Expires   time.Time `json:"expires"`
	LastUsed  time.Time `json:"last_used"`
	UserID    uint      `json:"-"`
}

func (*TwoFactorsCookie) Create

func (t *TwoFactorsCookie) Create() error

func (*TwoFactorsCookie) Delete

func (t *TwoFactorsCookie) Delete() error

func (*TwoFactorsCookie) Update

func (t *TwoFactorsCookie) Update() error

func (TwoFactorsCookie) Validate

func (t TwoFactorsCookie) Validate() error

type User

type User struct {
	BaseModel
	Email    string `gorm:"type:varchar(100);unique_index" json:"email" validate:"email,required"`
	Password string `gorm:"not null" json:"-"`

	// todo find out if i can remove this
	Entries []Entry `json:"-"`
	Labels  []Label `json:"-"`

	TwoFactorsCookies []TwoFactorsCookie `json:"two_factors_cookies"`

	// Stored encrypted
	OTPSecret        string `json:"-"`
	HasRegisteredOTP bool   `json:"has_registered_otp"`
}

func (*User) Create

func (user *User) Create() error

func (*User) Delete

func (user *User) Delete() error

func (*User) Update

func (user *User) Update() error

func (User) Validate

func (user User) Validate() error

Jump to

Keyboard shortcuts

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