db

package
v0.0.0-...-7f41272 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2017 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Dates

	ID                         int    `db:"id"`
	FilterID                   int    `db:"filter_id"`
	Negate                     bool   `db:"negate"`
	Type                       string `db:"type"`
	PayloadAction              string `db:"payload_action"`
	PayloadIssueLabel          string `db:"payload_issue_label"`
	PayloadIssueMilestoneTitle string `db:"payload_issue_milestone_title"`
	PayloadIssueTitleRegexp    string `db:"payload_issue_title_regexp"`
	PayloadIssueBodyRegexp     string `db:"payload_issue_body_regexp"`
	ComparePublic              bool   `db:"compare_public"`
	Public                     bool   `db:"public"`
	OrganizationID             int    `db:"organization_id"`
	RepositoryID               int    `db:"repository_id"`
}

Condition represents a single condition from the conditions table.

func (Condition) GHCondition

func (c Condition) GHCondition() ghfilter.Condition

func (Condition) String

func (c Condition) String() string

type DB

type DB interface {
	// Users returns a list of active users that need are scheduled to be polled.
	Users(context.Context) ([]User, error)
	// User returns a single user from the database, returns nil if no user was found.
	User(ctx context.Context, userID int) (*User, error)
	// UserUpdate updates a user in the database.
	UserUpdate(context.Context, *User) error
	// UsersFilters returns all filters for a User ID.
	UsersFilters(ctx context.Context, userID int) ([]Filter, error)
	// Filter returns a single filter from the database, returns nil if no filter found.
	Filter(ctx context.Context, filterID int) (*Filter, error)
	// FilterUpdate updates a filter in the database.
	FilterUpdate(context.Context, *Filter) error
	// Condition returns a single condition from the database, returns nil if no condition found.
	Condition(ctx context.Context, conditionID int) (*Condition, error)
	// ConditionDelete deletes a userID's condition from the database.
	ConditionDelete(ctsx context.Context, userID, conditionID int) error
	// ConditionCreate inserts a condition into the database.
	ConditionCreate(context.Context, *Condition) (conditionID int, err error)
	// SetUsersNextUpdate
	SetUsersPollResult(ctx context.Context, userID int, lastCreatedAt time.Time, nextUpdate time.Time) error
	// GitHubLogin logs a user in via GitHub, if a user already exists with the same
	// githubID, the user's accessToken is updated, else a new user is created.
	GitHubLogin(ctx context.Context, email string, githubID int, githubLogin string, token *oauth2.Token) (userID int, err error)
}

DB represents a database.

type Dates

type Dates struct {
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

type Filter

type Filter struct {
	Dates
	ID     int `db:"id"`
	UserID int `db:"user_id"`
	// If discard is true, the filter matching causes an event to be discarded
	// instead of accepted.
	OnMatchDiscard bool `db:"on_match_discard"`

	Conditions []Condition
}

Filter represents a single filter from the filters table.

func (*Filter) Matches

func (f *Filter) Matches(event *github.Event) bool

Matches if filter matches an event.

type SQLDB

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

func NewSQLDB

func NewSQLDB(driver string, dbConn *sql.DB) *SQLDB

func (*SQLDB) Condition

func (db *SQLDB) Condition(ctx context.Context, conditionID int) (*Condition, error)

Condition implements the DB interface.

func (*SQLDB) ConditionCreate

func (db *SQLDB) ConditionCreate(ctx context.Context, condition *Condition) (int, error)

ConditionCreate implements the DB interface.

func (*SQLDB) ConditionDelete

func (db *SQLDB) ConditionDelete(ctx context.Context, userID, conditionID int) error

ConditionDelete implements the DB interface.

func (*SQLDB) Filter

func (db *SQLDB) Filter(ctx context.Context, filterID int) (*Filter, error)

Filter implements the DB interface.

func (*SQLDB) FilterUpdate

func (db *SQLDB) FilterUpdate(ctx context.Context, filter *Filter) error

FilterUpdate implements the DB interface.

func (*SQLDB) GitHubLogin

func (db *SQLDB) GitHubLogin(ctx context.Context, email string, githubID int, githubLogin string, token *oauth2.Token) (int, error)

GitHubLogin implements the DB interface.

func (*SQLDB) SetUsersPollResult

func (db *SQLDB) SetUsersPollResult(ctx context.Context, userID int, lastCreatedAt, nextPoll time.Time) error

SetUsersPollResult implements the DB interface.

func (*SQLDB) User

func (db *SQLDB) User(ctx context.Context, userID int) (*User, error)

func (*SQLDB) UserUpdate

func (db *SQLDB) UserUpdate(ctx context.Context, user *User) error

UserUpdate implements the DB interface.

func (*SQLDB) Users

func (db *SQLDB) Users(_ context.Context) ([]User, error)

Users implements the DB interface.

func (*SQLDB) UsersFilters

func (db *SQLDB) UsersFilters(ctx context.Context, userID int) ([]Filter, error)

UsersFilters implements the DB interface.

type User

type User struct {
	Dates

	ID int `db:"id"`

	Email          string `db:"email"`
	GitHubID       int    `db:"github_id"`
	GitHubLogin    string `db:"github_login"`
	GitHubTokenRaw []byte `db:"github_token"`
	GitHubToken    *oauth2.Token

	FilterDefaultDiscard bool `db:"filter_default_discard"`

	EventLastCreatedAt time.Time // the latest created at event for the customer
	EventNextPoll      time.Time // time when the next update should occur
}

Jump to

Keyboard shortcuts

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