models

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BDB *bbolt.DB

BDB is a transaction in the simple BBolt database for fulfilling database needs when a full blown SQL server is not required

View Source
var DB *pop.Connection

DB is a connection to your database to be used throughout your application.

Functions

func BBoltTransaction

func BBoltTransaction(db *bbolt.DB) buffalo.MiddlewareFunc

BBoltTransaction is a piece of Buffalo middleware that wraps each request in a BBoltDB transaction. The transaction will automatically get committed if there's no errors and the response status code is a 2xx or 3xx, otherwise it'll be rolled back. It will also add a field to the log, "bdb", that shows the total duration spent during the request writing + spilling + re-balancing. This function is nearly an identical copy of pop's Transaction() just adapted to BBolt. Databases should be defined/initialized in models/models.go One important thing to not is that a writable transaction locks the database to other writable transaction, which means only one transaction will be processed if there are multiple goroutines waiting to read/write as only ONE read/write tx can exist at a time. This may also not scale well if there are many random write operations happening in a single transaction. BBolt is more adept at small operations. see https://github.com/boltdb/bolt#caveats--limitations for more information.

func DBToJSON added in v0.3.0

func DBToJSON(w io.Writer) error

DBToJSON encodes the site's SQL structure to json

Types

type ByArchived

type ByArchived []Topic

ByArchived slice of Topics. sorted by age. Archived topics last

func (ByArchived) Len

func (t ByArchived) Len() int

func (ByArchived) Less

func (t ByArchived) Less(i, j int) bool

func (ByArchived) Swap

func (t ByArchived) Swap(i, j int)

type ByVotes added in v0.3.0

type ByVotes []Topic

ByVotes sorts primarily by archived, then by votes, lastly by creation date

func (ByVotes) Len added in v0.3.0

func (t ByVotes) Len() int

func (ByVotes) Less added in v0.3.0

func (t ByVotes) Less(i, j int) bool

func (ByVotes) Swap added in v0.3.0

func (t ByVotes) Swap(i, j int)

type Categories

type Categories []Category

Categories is not required by pop and may be deleted

func (Categories) Len

func (c Categories) Len() int

func (Categories) Less

func (c Categories) Less(i, j int) bool

func (Categories) String

func (c Categories) String() string

String is not required by pop and may be deleted

func (Categories) Swap

func (c Categories) Swap(i, j int)

type Category

type Category struct {
	ID             uuid.UUID    `json:"id" db:"id"`
	Title          string       `json:"title" db:"title" form:"title"`
	Description    nulls.String `json:"description" db:"description" form:"description"`
	Subscribers    slices.UUID  `json:"subscribers" db:"subscribers"`
	ParentCategory nulls.UUID   `json:"parent_category" db:"parent_category"`
	CreatedAt      time.Time    `json:"created_at" db:"created_at"`
	UpdatedAt      time.Time    `json:"updated_at" db:"updated_at"`
}

Category is used by pop to map your categories database table to your go code.

func (*Category) AddSubscriber

func (c *Category) AddSubscriber(id uuid.UUID)

AddSubscriber add a uuid to category.Subscribers

func (*Category) RemoveSubscriber

func (c *Category) RemoveSubscriber(id uuid.UUID)

RemoveSubscriber remove a uuid from category.Subscribers

func (Category) String

func (c Category) String() string

String is not required by pop and may be deleted

func (*Category) Validate

func (c *Category) Validate(tx *pop.Connection) (*validate.Errors, error)

Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. This method is not required and may be deleted.

func (*Category) ValidateCreate

func (c *Category) ValidateCreate(tx *pop.Connection) (*validate.Errors, error)

ValidateCreate gets run every time you call "pop.ValidateAndCreate" method. This method is not required and may be deleted.

func (*Category) ValidateUpdate

func (c *Category) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)

ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method. This method is not required and may be deleted.

type Evaluation

type Evaluation struct {
	ID          uuid.UUID    `json:"id" db:"id"`
	Title       string       `json:"title" db:"title" form:"title"`
	Description string       `json:"description" db:"description" form:"description"`
	Content     string       `json:"content" db:"content" form:"content"`
	Solution    string       `json:"solution" db:"solution" form:"solution"`
	Hidden      bool         `json:"hidden" db:"hidden" form:"hidden"`
	Deleted     bool         `json:"deleted" db:"deleted" form:"deleted"`
	Inputs      nulls.String `json:"inputs" db:"inputs" form:"stdin"`
	CreatedAt   time.Time    `json:"created_at" db:"created_at"`
	UpdatedAt   time.Time    `json:"updated_at" db:"updated_at"`
}

Evaluation is used by pop to map your evaluations database table to your go code.

func (Evaluation) String

func (e Evaluation) String() string

String is not required by pop and may be deleted

func (*Evaluation) Validate

func (e *Evaluation) Validate(tx *pop.Connection) (*validate.Errors, error)

Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. This method is not required and may be deleted.

type Evaluations

type Evaluations []Evaluation

Evaluations is not required by pop and may be deleted

func (Evaluations) Len

func (e Evaluations) Len() int

func (Evaluations) Less

func (e Evaluations) Less(i, j int) bool

func (Evaluations) String

func (e Evaluations) String() string

String is not required by pop and may be deleted

func (Evaluations) Swap

func (e Evaluations) Swap(i, j int)

type Forum

type Forum struct {
	ID          uuid.UUID   `json:"id" db:"id"`
	Title       string      `json:"title" db:"title" form:"title"`
	Description string      `json:"description" db:"description" form:"description"`
	Defcon      string      `json:"defcon" db:"defcon" form:"access"` // level of access needed to see forum
	Staff       slices.UUID `json:"staff" db:"staff" form:"-"`        // moderator IDs
	CreatedAt   time.Time   `json:"created_at" db:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at" db:"updated_at"`

	StaffEmails string `form:"staffemail" db:"-"`
}

Forum is used by pop to map your forums database table to your go code.

func (Forum) LogoImage

func (f Forum) LogoImage(opt render.Data) template.HTML

LogoImage returns html for inserting forum logo straight into template

func (Forum) String

func (f Forum) String() string

String is not required by pop and may be deleted

func (*Forum) Validate

func (f *Forum) Validate(tx *pop.Connection) (*validate.Errors, error)

Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. This method is not required and may be deleted.

func (*Forum) ValidateCreate

func (f *Forum) ValidateCreate(tx *pop.Connection) (*validate.Errors, error)

ValidateCreate gets run every time you call "pop.ValidateAndCreate" method. This method is not required and may be deleted.

func (*Forum) ValidateUpdate

func (f *Forum) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)

ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method. This method is not required and may be deleted.

type Forums

type Forums []Forum

Forums is not required by pop and may be deleted

func (Forums) String

func (f Forums) String() string

String is not required by pop and may be deleted

type Replies

type Replies []Reply

Replies and sort algorithm

func (Replies) Len

func (r Replies) Len() int

func (Replies) Less

func (r Replies) Less(i, j int) bool

func (Replies) String

func (r Replies) String() string

String is not required by pop and may be deleted

func (Replies) Swap

func (r Replies) Swap(i, j int)

type Reply

type Reply struct {
	ID        uuid.UUID `json:"id" db:"id"`
	AuthorID  uuid.UUID `json:"author_id" db:"author_id"`
	TopicID   uuid.UUID `json:"topic_id" db:"topic_id"`
	Content   string    `json:"content" db:"content" form:"content"`
	Deleted   bool      `json:"deleted" db:"deleted"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`

	Author *User  `json:"-" db:"-"`
	Topic  *Topic `json:"-" db:"-"`
}

Reply is used by pop to map your replies database table to your go code.

func (Reply) String

func (r Reply) String() string

String is not required by pop and may be deleted

func (*Reply) Validate

func (r *Reply) Validate(tx *pop.Connection) (*validate.Errors, error)

Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. This method is not required and may be deleted.

type Submission added in v0.4.0

type Submission struct {
	ID                 uuid.UUID `json:"id" db:"id"`
	ForumID            uuid.UUID `json:"forum_id" db:"forum_id"`
	IsTemplate         bool      `json:"is_template" db:"is_template"`
	UserID             uuid.UUID `json:"user_id" db:"user_id"`
	RequireEmailVerify bool      `json:"require_email_verify" db:"require_email_verify"`
	// Template fields (isTemplate == true)
	Title       nulls.String `json:"title" db:"title"`
	Description nulls.String `json:"description" db:"description"`
	Schemas     nulls.String `json:"schemas" db:"schemas"`
	Hidden      bool         `json:"hidden" db:"hidden"`
	Deleted     bool         `json:"deleted" db:"deleted"`
	Editable    bool         `json:"editable" db:"editable"`
	Anonymous   bool         `json:"anonymous" db:"anonymous"`
	// Response fields (isTemplate == false)
	SubmissionID  uuid.NullUUID   `json:"submission_id" db:"submission_id"`
	Response      nulls.String    `json:"response" db:"response"`
	HasAttachment bool            `json:"has_attachment" db:"has_attachment"`
	Zip           nulls.ByteSlice `json:"zip" db:"zip"`
	CreatedAt     time.Time       `json:"created_at" db:"created_at"`
	UpdatedAt     time.Time       `json:"updated_at" db:"updated_at"`
}

Submission is used by pop to map your submissions database table to your go code. Submission is basically a google forms response or actual form template mockup

func (Submission) String added in v0.4.0

func (s Submission) String() string

String is not required by pop and may be deleted

func (*Submission) Validate added in v0.4.0

func (s *Submission) Validate(tx *pop.Connection) (*validate.Errors, error)

Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.

func (*Submission) ValidateCreate added in v0.4.0

func (s *Submission) ValidateCreate(tx *pop.Connection) (*validate.Errors, error)

ValidateCreate gets run every time you call "pop.ValidateAndCreate" method. This method is not required and may be deleted.

func (*Submission) ValidateUpdate added in v0.4.0

func (s *Submission) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)

ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method. This method is not required and may be deleted.

type Submissions added in v0.4.0

type Submissions []Submission

Submissions is not required by pop and may be deleted

func (Submissions) String added in v0.4.0

func (s Submissions) String() string

String is not required by pop and may be deleted

type Topic

type Topic struct {
	ID          uuid.UUID   `json:"id" db:"id"`
	Title       string      `json:"title" db:"title" form:"title"`
	Content     string      `json:"content" db:"content" form:"content"`
	AuthorID    uuid.UUID   `json:"author_id" db:"author_id"`
	CategoryID  uuid.UUID   `json:"category_id" db:"category_id" `
	Voters      slices.UUID `json:"voters" db:"voters"`
	Archived    bool        `jsonL:"archived" db:"archived" form:"archive"`
	Deleted     bool        `json:"deleted" db:"deleted"`
	Subscribers slices.UUID `json:"subscribers" db:"subscribers"`
	CreatedAt   time.Time   `json:"created_at" db:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at" db:"updated_at"`

	Author   *User     `json:"-" db:"-"`
	Category *Category `json:"-" db:"-"`
	Replies  Replies   `json:"-" db:"-"`
}

Topic is used by pop to map your topics database table to your go code.

func (*Topic) AddSubscriber

func (t *Topic) AddSubscriber(id uuid.UUID)

AddSubscriber add id to topic.subscribers

func (*Topic) AddVoter added in v0.3.0

func (t *Topic) AddVoter(id uuid.UUID)

AddVoter add id to topic.voters

func (Topic) Authors

func (t Topic) Authors() Users

Authors returns a slice of users including the main topic author and also reply authors.

func (Topic) LastUpdate

func (t Topic) LastUpdate() time.Time

LastUpdate returns last time topic was edited, created or replied to

func (*Topic) RemoveSubscriber

func (t *Topic) RemoveSubscriber(id uuid.UUID)

RemoveSubscriber remove subscriber from topic.Subscribers

func (*Topic) RemoveVoter added in v0.3.0

func (t *Topic) RemoveVoter(id uuid.UUID)

RemoveVoter remove subscriber from topic.Voters

func (Topic) String

func (t Topic) String() string

String is not required by pop and may be deleted

func (Topic) Subscribed

func (t Topic) Subscribed(id uuid.UUID) bool

Subscribed checks if id in Topic.Subscribers

func (*Topic) Validate

func (t *Topic) Validate(tx *pop.Connection) (*validate.Errors, error)

Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. This method is not required and may be deleted.

func (Topic) Voted added in v0.3.0

func (t Topic) Voted(id uuid.UUID) bool

Voted checks if id in Topic.Voters

func (Topic) Votes added in v0.3.0

func (t Topic) Votes() int

Votes returns number of votes a topic has

type Topics

type Topics []Topic

Topics slice of Topics. sorted by age.

func (Topics) Len

func (t Topics) Len() int

func (Topics) Less

func (t Topics) Less(i, j int) bool

func (Topics) String

func (t Topics) String() string

String is not required by pop and may be deleted

func (Topics) Swap

func (t Topics) Swap(i, j int)

type User

type User struct {
	ID            uuid.UUID   `json:"id" db:"id"`
	Name          string      `json:"name" db:"name"`
	Nick          string      `json:"nick" db:"nick" form:"nick"`
	Provider      string      `json:"provider" db:"provider"`
	ProviderID    string      `json:"provider_id" db:"provider_id"`
	Email         string      `json:"email" db:"email"`
	Role          string      `json:"role" db:"role"`
	AvatarURL     string      `json:"avatar" db:"avatar_url"`
	Subscriptions slices.UUID `json:"subscriptions" db:"subscriptions"`
	CreatedAt     time.Time   `json:"created_at" db:"created_at"`
	UpdatedAt     time.Time   `json:"updated_at" db:"updated_at"`

	Theme string `db:"-" json:"-" form:"code-theme"`
}

User is used by pop to map your users database table to your go code.

func (*User) AddSubscription

func (u *User) AddSubscription(id uuid.UUID)

AddSubscription add uuid to user.Subscriptions

func (User) Icon

func (u User) Icon(label string) template.HTML

Icon returns html for user icon

func (User) ImageSrc

func (u User) ImageSrc() string

ImageSrc for now just return u.AvatarURL

func (User) IsAuthor

func (u User) IsAuthor(id uuid.UUID) bool

IsAuthor checks if user.ID is equal to the uuid

func (*User) RemoveSubscription

func (u *User) RemoveSubscription(id uuid.UUID)

RemoveSubscription safe way to update models.User Subscriptions.

func (User) String

func (u User) String() string

String is not required by pop and may be deleted

func (User) Subscribed

func (u User) Subscribed(id uuid.UUID) bool

Subscribed returns true if id is in user.Subscriptions

func (*User) Validate

func (u *User) Validate(tx *pop.Connection) (*validate.Errors, error)

Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. This method is not required and may be deleted.

func (*User) ValidateCreate

func (u *User) ValidateCreate(tx *pop.Connection) (*validate.Errors, error)

ValidateCreate gets run every time you call "pop.ValidateAndCreate" method. This method is not required and may be deleted.

func (*User) ValidateUpdate

func (u *User) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)

ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method. This method is not required and may be deleted.

type Users

type Users []User

Users is not required by pop and may be deleted

func (Users) String

func (u Users) String() string

String is not required by pop and may be deleted

Jump to

Keyboard shortcuts

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