1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package orm
- import (
- "net/http"
- "github.com/jinzhu/gorm"
- _ "github.com/jinzhu/gorm/dialects/mysql"
- )
- type IDer interface {
- GetID() uint
- }
- type Timetable [][]Activity
- type Person interface {
- GetCredential() *Credential
- }
- type Address struct {
- City string
- Street string
- ZipCode string
- Country string
- }
- type Location struct {
- Id string
- Name string
- Address *Address
- }
- type Room struct {
- Id string
- Name string
- Capacity int
- Location *Location
- }
- type Desk struct {
- Id string
- Name string
- Students []*Student
- Teacher *Teacher
- }
- type GetFn func(map[string]string, *http.Request) (interface{}, error)
- var currDB *gorm.DB
- func New(connection string) (*gorm.DB, error) {
- db, err := gorm.Open("mysql", connection)
- if err != nil {
- return nil, err
- }
- return db, nil
- }
- func Use(db *gorm.DB) {
- currDB = db
- }
- func DB() *gorm.DB {
- return currDB
- }
- func AutoMigrate() {
- if err := currDB.AutoMigrate(
- &School{},
- &Subject{},
- &Teacher{},
- &Class{},
- &Activity{},
- &Department{},
- &Student{},
- &Office{},
- &Administrative{},
- &Document{},
- &Job{},
- &File{},
- &GeneratorType{},
- &Log{},
- &Group{},
- &Operator{},
- ).Error; err != nil {
- panic(err)
- }
- }
|