Documentation
¶
Overview ¶
Package database provides basic (read: fragile) object relational mapping between structs and database tables.
Index ¶
- func FlipSwitch(switchDB *sql.DB) error
- func GetAppDB(switchDB *sql.DB, reverse bool) (res *sql.DB, err error)
- func Insert(db *sql.DB, q Queryer) error
- func ParseSqlFile(path string) ([]string, error)
- func SetupDB(db *sql.DB) error
- type Class
- type Classes
- type Dept
- type MeetingTime
- type Parent
- type Queryer
- type Sect
- func (s Sect) GetGradesTokens() []map[string]bool
- func (s Sect) GetMeetingTimes() ([]MeetingTime, error)
- func (s Sect) GetOtherTokens() []map[string]bool
- func (s Sect) GetRestriction() []map[string]bool
- func (s Sect) IsFreshmen() bool
- func (s Sect) IsOpen() bool
- func (s Sect) IsQuizSection() bool
- func (s Sect) IsWithdrawal() bool
- func (s Sect) PrimaryKey() interface{}
- func (s Sect) TableName() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FlipSwitch ¶
Flip switch changes the value stored in the 'switch db' from 0 to 1 or from 1 to 0.
func ParseSqlFile ¶
ParseSqlFile parses a SQL file into a slice of SQL commands (delimited by semicolons). Semicolons are included in the slice of commands. Comments (starting with '--') are ignored.
Types ¶
type Class ¶
type Class struct { DeptAbbreviation string // foreign key AbbreviationCode string // primary key Abbreviation string Code string Title string Description string Index int }
A Class is UW class that has many sections.
func (Class) DescriptionHTML ¶
DescriptionHTML outputs non-escaped HTML of a class's for use in a template.
func (Class) PrimaryKey ¶
func (c Class) PrimaryKey() interface{}
PrimaryKey returns the class's AbbreviationCode.
type Classes ¶
type Classes []Class
Classes wraps a slice of Class structs so they can implement a ForeignKey method.
type Dept ¶
A Department is a UW department that has many classes
func (Dept) PrimaryKey ¶
func (d Dept) PrimaryKey() interface{}
PrimaryKey returns the dept's Abbreviation.
type MeetingTime ¶
A MeetingTime represents when a class is held. Some Sect's have multiple meeting times. A MeetingTime belongs to the Sect with Sln 'SectSln'.
func (MeetingTime) MapDays ¶
func (m MeetingTime) MapDays() map[string]bool
MapDays returns a map of possible days to booleans depending on what days this Section is held.
type Parent ¶
type Parent interface {
ForeignKey() interface{}
}
A Parent is a type that will be referenced by children. ForeignKey returns whatever the children will store to establish their relationship to the parent.
type Queryer ¶
type Queryer interface { PrimaryKey() interface{} TableName() string }
Structs that implement Queryer can be stored and retrieved from the database with Put and Get, respectively. PrimaryKey returns the unique identifier for the struct. TableName returns the name of the database table that should be queried. NOTE: The corresponding database table must be setup with the proper field values.
type Sect ¶
type Sect struct { ClassDeptAbbreviation string // foreign key Restriction string SLN string // primary key Section string Credit string MeetingTimes string // JSON representation, TODO (kvu787): represent as seperate struct Instructor string Status string TakenSpots int TotalSpots int Grades string Fee string Other string Info string }
A Class is a UW class represented on the time schedule.
func (Sect) GetGradesTokens ¶
GetGradesTokens returns a map of possible grade tokens to booleans depending on if they apply to this Section.
func (Sect) GetMeetingTimes ¶
func (s Sect) GetMeetingTimes() ([]MeetingTime, error)
GetMeetingTimes parses the JSON representation of meeting times from the Section. Returns a slice of MeetingTime structs, or an empty slice if the section has no MeetingTime's.
func (Sect) GetOtherTokens ¶
GetOtherTokens returns a map of possible other tokens to booleans depending on if they apply to this Section.
func (Sect) GetRestriction ¶
GetRestriction returns a map of possible restriction symbols to booleans depending on if they apply to this Section.
func (Sect) IsFreshmen ¶
IsFreshmen indicates if this Sect is restricted to freshmen by looking for key phrases/words in Sect.Info. TODO (kvu787): use regexps
func (Sect) IsQuizSection ¶
IsQuizSection indicates if this Sect is a quiz section.
func (Sect) IsWithdrawal ¶
IsWithdrawal indicates if this Sect pending withdrawal by looking for key phrases/words in Sect.Info.