db

package
v0.0.0-...-b3ee4c8 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2017 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID           int64
	Name         string `gorm:"not null"`
	AccessToken  string `gorm:"not null"`
	AccessSecret string `gorm:"not null"`
	QueueLength  int64  `gorm:"not null"`
}

Account represents an individual Twitter account with API credentials.

type Config

type Config struct {
	Driver string
	Args   string
}

Config provides parameters for connecting to the database.

type Connection

type Connection struct {
	C *gorm.DB
	// contains filtered or unexported fields
}

Connection represents a socket connection to the database. The C member may be used directly to perform queries.

func Connect

func Connect(cfg *Config) (*Connection, error)

Connect makes an attempt to connect to the database using the provided configuration.

func (*Connection) Close

func (c *Connection) Close()

Close disconnects from the database.

func (*Connection) Migrate

func (c *Connection) Migrate() error

Migrate performs all pending database migrations.

func (*Connection) Transaction

func (c *Connection) Transaction(fn func(*Connection) error) error

Transaction executes the provided callback in a transaction, automatically rolling back the database if an error occurs and committing the changes if none occurs.

type QueueItem

type QueueItem struct {
	ID        int64
	Date      time.Time
	Text      string   `gorm:"not null"`
	MediaURL  string   `gorm:"not null"`
	User      *User    `gorm:"ForeignKey:UserID"`
	UserID    int64    `sql:"type:int REFERENCES users(id) ON DELETE CASCADE"`
	Account   *Account `gorm:"ForeignKey:AccountID"`
	AccountID int64    `sql:"type:int REFERENCES accounts(id) ON DELETE CASCADE"`
}

QueueItem represents a suggestion that has been approved and is queued for tweeting.

type Schedule

type Schedule struct {
	ID        int64
	Cron      string    `gorm:"not null"`
	NextRun   time.Time `gorm:"not null"`
	Account   *Account  `gorm:"ForeignKey:AccountID"`
	AccountID int64     `sql:"type:int REFERENCES accounts(id) ON DELETE CASCADE"`
}

Schedule represents a specific time at which a queued tweet should be sent from an account. Cron notation is used for specifying the times. Each account may have multiple schedules.

func (*Schedule) Calculate

func (s *Schedule) Calculate() error

Calculate determines when the next run should be based on the schedule. This method does NOT save the model.

type Suggestion

type Suggestion struct {
	ID        int64
	Date      time.Time
	Text      string   `gorm:"not null"`
	MediaURL  string   `gorm:"not null"`
	User      *User    `gorm:"ForeignKey:UserID"`
	UserID    int64    `sql:"type:int REFERENCES users(id) ON DELETE CASCADE"`
	Account   *Account `gorm:"ForeignKey:AccountID"`
	AccountID int64    `sql:"type:int REFERENCES accounts(id) ON DELETE CASCADE"`
	Votes     []*Vote  `gorm:"ForeignKey:SuggestionID"`
	VoteCount int64    `gorm:"not null"`
}

Suggestion represents a tweet proposed by a user but not yet queued for tweeting by an admin.

type Tweet

type Tweet struct {
	ID        int64
	TweetID   int64
	Date      time.Time
	Text      string   `gorm:"not null"`
	MediaURL  string   `gorm:"not null"`
	User      *User    `gorm:"ForeignKey:UserID"`
	UserID    int64    `sql:"type:int REFERENCES users(id) ON DELETE CASCADE"`
	Account   *Account `gorm:"ForeignKey:AccountID"`
	AccountID int64    `sql:"type:int REFERENCES accounts(id) ON DELETE CASCADE"`
}

Tweet represents a queued item that has since been tweeted.

type User

type User struct {
	ID       int64
	Username string `gorm:"not null;unique_index"`
	Password string `gorm:"not null"`
	Email    string `gorm:"not null"`
	IsActive bool
	IsAdmin  bool
}

User represents an individual user that can login to the website. Regular users are able to suggest tweets and admins are able to edit and queue them.

Passwords are salted and hashed with bcrypt. The email address is used for displaying gravatars and password resets.

func (*User) Authenticate

func (u *User) Authenticate(password string) error

Authenticate hashes the password and compares it to the value stored in the database. An error is returned if the values do not match.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword salts and hashes the user's password. It does not store the new value in the database.

type Vote

type Vote struct {
	ID           int64
	User         *User       `gorm:"ForeignKey:UserID"`
	UserID       int64       `sql:"type:int REFERENCES users(id) ON DELETE CASCADE"`
	Suggestion   *Suggestion `gorm:"ForeignKey:SuggestionID"`
	SuggestionID int64       `sql:"type:int REFERENCES suggestions(id) ON DELETE CASCADE"`
}

Vote represents a vote for a specific suggestion.

Jump to

Keyboard shortcuts

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