database

package
v0.0.0-...-20a2c84 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2013 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package database provides basic (read: fragile) object relational mapping between structs and database tables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlipSwitch

func FlipSwitch(switchDB *sql.DB) error

Flip switch changes the value stored in the 'switch db' from 0 to 1 or from 1 to 0.

func GetAppDB

func GetAppDB(switchDB *sql.DB, reverse bool) (res *sql.DB, err error)

func Insert

func Insert(db *sql.DB, q Queryer) error

Insert inserts a Queryer struct into the database.

func ParseSqlFile

func ParseSqlFile(path string) ([]string, error)

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.

func SetupDB

func SetupDB(db *sql.DB) error

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

func (c Class) DescriptionHTML() template.HTML

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.

func (Class) TableName

func (c Class) TableName() string

TableName returns the name of the SQL table corresponding to Class structs.

type Classes

type Classes []Class

Classes wraps a slice of Class structs so they can implement a ForeignKey method.

type Dept

type Dept struct {
	Title        string
	Abbreviation string // primary key
	Link         string
}

A Department is a UW department that has many classes

func (Dept) PrimaryKey

func (d Dept) PrimaryKey() interface{}

PrimaryKey returns the dept's Abbreviation.

func (Dept) TableName

func (d Dept) TableName() string

TableName returns the name of the SQL table corresponding to Dept structs.

type MeetingTime

type MeetingTime struct {
	Days     string
	Time     string
	Building string
	Room     string
}

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.

func Select

func Select(db *sql.DB, q Queryer, filters string) ([]Queryer, error)

Select uses an empty Queryer struct to query the database and return a slice of the corresponding Queryer structs. By default it returns records in the form: 'SELECT * FROM [q.TableName()] [additional SQL clauses]...'. Additional SQL clauses can be specified in the filters parameter.

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

func (s Sect) GetGradesTokens() []map[string]bool

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

func (s Sect) GetOtherTokens() []map[string]bool

GetOtherTokens returns a map of possible other tokens to booleans depending on if they apply to this Section.

func (Sect) GetRestriction

func (s Sect) GetRestriction() []map[string]bool

GetRestriction returns a map of possible restriction symbols to booleans depending on if they apply to this Section.

func (Sect) IsFreshmen

func (s Sect) IsFreshmen() bool

IsFreshmen indicates if this Sect is restricted to freshmen by looking for key phrases/words in Sect.Info. TODO (kvu787): use regexps

func (Sect) IsOpen

func (s Sect) IsOpen() bool

IsOpen indicates if this Sect has open spots.

func (Sect) IsQuizSection

func (s Sect) IsQuizSection() bool

IsQuizSection indicates if this Sect is a quiz section.

func (Sect) IsWithdrawal

func (s Sect) IsWithdrawal() bool

IsWithdrawal indicates if this Sect pending withdrawal by looking for key phrases/words in Sect.Info.

func (Sect) PrimaryKey

func (s Sect) PrimaryKey() interface{}

PrimaryKey returns the sect's SLN.

func (Sect) TableName

func (s Sect) TableName() string

TableName returns the name of the SQL table corresponding to Sect structs.

Jump to

Keyboard shortcuts

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