Documentation
¶
Overview ¶
Package database contains utilities to connect to the default Postgres (+ Timescale) database. It implements the models and the API to interact with the database.
Index ¶
- Constants
- Variables
- type Bool
- type Check
- type Config
- type Conn
- func (c *Conn) AddChecksToPage(ctx context.Context, ownerID, pageID uint, checkIDs []string) error
- func (c *Conn) AddTeamMemberToPage(ctx context.Context, ownerID, pageID, memberID uint, role string) (*PageTeam, error)
- func (c *Conn) CreateCheck(ctx context.Context, ownerID uint, check *Check) (*Check, error)
- func (c *Conn) CreateIncident(ctx context.Context, ownerID, pageID uint, incident *Incident) (*Incident, error)
- func (c *Conn) CreatePage(ctx context.Context, ownerID uint, page *Page) (*Page, error)
- func (c *Conn) CreatePayload(ctx context.Context, ownerID uint, checkID string, payload *Payload) (*Payload, error)
- func (c *Conn) CreateUser(ctx context.Context, user *User) (*User, error)
- func (c *Conn) DeleteCheck(ctx context.Context, ownerID uint, checkID string) error
- func (c *Conn) DeleteIncident(ctx context.Context, ownerID, pageID, incidentID uint) error
- func (c *Conn) DeletePage(ctx context.Context, ownerID, pageID uint) error
- func (c *Conn) DeletePayload(ctx context.Context, ownerID, payloadID uint, checkID string) error
- func (c *Conn) DeleteUserByEmail(ctx context.Context, email string) error
- func (c *Conn) DeleteUserByID(ctx context.Context, id uint) error
- func (c *Conn) GetCheck(ctx context.Context, ownerID uint, checkID string, opts GetCheckOpts) (*Check, error)
- func (c *Conn) GetIncident(ctx context.Context, ownerID, pageID, incidentID uint, opts GetIncidentOpts) (*Incident, error)
- func (c *Conn) GetPage(ctx context.Context, ownerID, pageID uint, opts GetPageOpts) (*Page, error)
- func (c *Conn) GetPayload(ctx context.Context, ownerID, payloadID uint, checkID string, ...) (*Payload, error)
- func (c *Conn) GetUserByEmail(ctx context.Context, email string, opts GetUserOpts) (*User, error)
- func (c *Conn) GetUserByID(ctx context.Context, id uint, opts GetUserOpts) (*User, error)
- func (c *Conn) RemoveChecksFromPage(ctx context.Context, ownerID, pageID uint, checkIDs []string) error
- func (c *Conn) RemoveTeamMemberFromPage(ctx context.Context, ownerID, pageID, memberID uint) error
- func (c *Conn) UpdateCheck(ctx context.Context, ownerID uint, checkID string, check *Check) (*Check, error)
- func (c *Conn) UpdateIncident(ctx context.Context, ownerID, pageID, incidentID uint, incident *Incident) (*Incident, error)
- func (c *Conn) UpdatePage(ctx context.Context, ownerID, pageID uint, page *Page) (*Page, error)
- func (c *Conn) UpdatePayload(ctx context.Context, ownerID, payloadID uint, checkID string, payload *Payload) (*Payload, error)
- func (c *Conn) UpdateTeamMemberRole(ctx context.Context, ownerID, pageID, memberID uint, role string) (*PageTeam, error)
- func (c *Conn) UpdateUserByEmail(ctx context.Context, email string, user *User) (*User, error)
- func (c *Conn) UpdateUserByID(ctx context.Context, id uint, user *User) (*User, error)
- type GetCheckOpts
- type GetIncidentOpts
- type GetPageOpts
- type GetPayloadOpts
- type GetUserOpts
- type Incident
- type Page
- type PageTeam
- type Payload
- type User
Constants ¶
const ( RoleDefault = "DEFAULT" RoleMaintainer = "MAINTAINER" RoleAdmin = "ADMIN" )
Various roles of a team member.
Variables ¶
var ( // ErrRecordNotFound is the error returned when the database has no matching // record. // // Since gorm v2 (1.20), it returns an error rather than a check using method, // so this error is just an alias of same error which can be used to check if // the record did not exist. ErrRecordNotFound = gorm.ErrRecordNotFound // ErrNilPointer is the error returned in case when the pointer is nil. This // can be checked using `errors.Unwrap`. ErrNilPointer = errors.New("pointer cannot be nil") )
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool rune
Bool for storing in models as a rune.
't', 'T', '1' and 1 represnt true, rest false.
type Check ¶
type Check struct { ID string `gorm:"primaryKey"` CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` OwnerID uint Owner User Title string `gorm:"NOT NULL"` Interval time.Duration `gorm:"DEFAULT:30"` Timeout time.Duration `gorm:"DEFAULT:30"` InputType string `gorm:"NOT NULL"` InputValue string `gorm:"NOT NULL"` OutputType string `gorm:"NOT NULL"` OutputValue string `gorm:"NOT NULL"` TargetType string `gorm:"NOT NULL"` TargetValue string `gorm:"NOT NULL"` Payloads []Payload `gorm:"foreignkey:CheckID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` }
Check model.
type Config ¶
type Config interface { GetName() string // Name of the database GetHost() string // Host of the database GetPort() uint16 // Port of the database GetUsername() string // Username of the database GetPassword() string // Password of the database IsSSLMode() bool // Should connect using SSL }
Config can be used to create a connection with the database.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is the database connection which can be used to access the API to interact with the database.
func (*Conn) AddChecksToPage ¶
AddChecksToPage adds relationship between the checks and the page, hence inserting checks into the page.
func (*Conn) AddTeamMemberToPage ¶
func (c *Conn) AddTeamMemberToPage( ctx context.Context, ownerID, pageID, memberID uint, role string, ) (*PageTeam, error)
AddTeamMemberToPage adds a new team member to the page with the given ID.
func (*Conn) CreateCheck ¶
CreateCheck creates a new check.
func (*Conn) CreateIncident ¶
func (c *Conn) CreateIncident(ctx context.Context, ownerID, pageID uint, incident *Incident) (*Incident, error)
CreateIncident creates a new incident.
func (*Conn) CreatePage ¶
CreatePage creates a new page.
func (*Conn) CreatePayload ¶
func (c *Conn) CreatePayload(ctx context.Context, ownerID uint, checkID string, payload *Payload) (*Payload, error)
CreatePayload creates a new payload.
func (*Conn) CreateUser ¶
CreateUser creates a new user in the database. It simply returns the user with the same email if the user exists.
func (*Conn) DeleteCheck ¶
DeleteCheck deletes the check with the given ID.
func (*Conn) DeleteIncident ¶
DeleteIncident deletes the incident with the given ID.
func (*Conn) DeletePage ¶
DeletePage deletes the page with the given ID.
func (*Conn) DeletePayload ¶
DeletePayload deletes the payload with the given ID.
func (*Conn) DeleteUserByEmail ¶
DeleteUserByEmail deletes a user entry.
func (*Conn) DeleteUserByID ¶
DeleteUserByID deletes a user entry.
func (*Conn) GetCheck ¶
func (c *Conn) GetCheck(ctx context.Context, ownerID uint, checkID string, opts GetCheckOpts) (*Check, error)
GetCheck gets a check from given checkID.
func (*Conn) GetIncident ¶
func (c *Conn) GetIncident( ctx context.Context, ownerID, pageID, incidentID uint, opts GetIncidentOpts, ) (*Incident, error)
GetIncident gets an incident from given incidentID.
func (*Conn) GetPayload ¶
func (c *Conn) GetPayload( ctx context.Context, ownerID, payloadID uint, checkID string, opts GetPayloadOpts, ) (*Payload, error)
GetPayload gets a payload from given payloadID.
func (*Conn) GetUserByEmail ¶
GetUserByEmail gets user by Email.
func (*Conn) GetUserByID ¶
GetUserByID gets user by ID.
func (*Conn) RemoveChecksFromPage ¶
func (c *Conn) RemoveChecksFromPage(ctx context.Context, ownerID, pageID uint, checkIDs []string) error
RemoveChecksFromPage removes relationship between the checks and the page, hence deleting checks from the page.
func (*Conn) RemoveTeamMemberFromPage ¶
RemoveTeamMemberFromPage removes the team member from the page.
func (*Conn) UpdateCheck ¶
func (c *Conn) UpdateCheck(ctx context.Context, ownerID uint, checkID string, check *Check) (*Check, error)
UpdateCheck updates a check with the given ID.
func (*Conn) UpdateIncident ¶
func (c *Conn) UpdateIncident( ctx context.Context, ownerID, pageID, incidentID uint, incident *Incident, ) (*Incident, error)
UpdateIncident updates a incident with the given ID.
func (*Conn) UpdatePage ¶
UpdatePage updates a page with the given ID.
func (*Conn) UpdatePayload ¶
func (c *Conn) UpdatePayload( ctx context.Context, ownerID, payloadID uint, checkID string, payload *Payload, ) (*Payload, error)
UpdatePayload updates a payload with the given ID.
func (*Conn) UpdateTeamMemberRole ¶
func (c *Conn) UpdateTeamMemberRole( ctx context.Context, ownerID, pageID, memberID uint, role string, ) (*PageTeam, error)
UpdateTeamMemberRole updates the role of a team member.
func (*Conn) UpdateUserByEmail ¶
UpdateUserByEmail updates the user for given email.
type GetCheckOpts ¶
GetCheckOpts are the options to preload check associations.
type GetIncidentOpts ¶
GetIncidentOpts are the options to preload payload associations.
type GetPageOpts ¶
GetPageOpts are the options to preload page associations.
type GetPayloadOpts ¶
GetPayloadOpts are the options to preload payload associations.
type GetUserOpts ¶
GetUserOpts are the get options for user relations. Objects are preloaded using the options set here.
type Incident ¶
type Incident struct { gorm.Model Owner User OwnerID uint PageID uint Page Page Title string `gorm:"NOT NULL"` Description string `gorm:"TYPE:text"` Resolved Bool `gorm:"DEFAULT:102;size:256"` TimeStamp time.Time `gorm:"NOT NULL"` Duration time.Duration `gorm:"NOT NULL"` }
Incident model.
type Page ¶
type Page struct { gorm.Model OwnerID uint Owner User Title string `gorm:"NOT NULL"` Description string `gorm:"TYPE:text"` Visibility Bool `gorm:"DEFAULT:102;size:256"` Checks []Check `gorm:"many2many:page_checks"` Incidents []Incident `gorm:"foreignkey:PageID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` Team []PageTeam `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` }
Page model.
type PageTeam ¶
type PageTeam struct { Page Page PageID uint `gorm:"primarKey;autoIncrement:false"` User User UserID uint `gorm:"primaryKey;autoIncrement:false"` Role string `gorm:"NOT NULL"` }
PageTeam model.
type Payload ¶
type Payload struct { gorm.Model Owner User OwnerID uint CheckID string Check Check Type string `gorm:"NOT NULL"` Value string `gorm:"NOT NULL;TYPE:text"` }
Payload model.
type User ¶
type User struct { gorm.Model Email string `gorm:"UNIQUE;NOT NULL"` Name string `gorm:"NOT NULL"` Checks []Check `gorm:"foreignkey:OwnerID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` Payloads []Payload `gorm:"foreignkey:OwnerID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` Pages []Page `gorm:"foreignkey:OwnerID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` TeamPages []PageTeam `gorm:"foreignkey:UserID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` Incidents []Incident `gorm:"foreignkey:OwnerID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` }
User model.