Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package models
- type User struct {
- UserName string `json: "username" gorm: "primary_key; type:TEXT"`
- Verified bool `json: "verified" gorm: "type : "BOOLEAN" `
- Password string `json: "password" gorm: "type: TEXT"`
- Token string `json: "token" sql:"-" gorm:"-" `
- Podcasts []Podcast `json: "podcasts" gorm: "ForeignKey:UserEmail"`
- }
- type UserTitle struct {
- UserName string `json: "username"`
- }
- type Message struct {
- Message string `json: "message"`
- }
- type Podcast struct {
- PodcastID uint `gorm: "primary_key; AUTO_INCREMENT; type:INTEGER"`
- UserEmail string `json: "useremail" gorm: "type:TEXT"`
- Icon string `json: "icon" gorm: "type:TEXT"`
- Name string `json: "name" gorm: "type: TEXT"`
- EpisodeNum int `json: "episodenum" gorm: "type:INTEGER; default:0"`
- Details string `json : "details" gorm: "type:TEXT"`
- Episodes []Episode `json: "episodes" gorm: "ForeignKey:PodID"`
- }
- type Episode struct {
- PodID uint `gorm: "type:INTEGER" json: "podid"`
- Created string `json: "created" gorm: "type: TEXT"`
- Updated string `json: "updated" gorm: "type: TEXT"`
- URL string `json: "url" gorm: "type: TEXT"`
- Downloads int32 `json: "downloads" gorm: "type: INTEGER; not null default:0"`
- Blurb string `json: "blurb" gorm: "type: TEXT"`
- }
- //in my main i call the following.
- conf := fmt.Sprintf("%s:%s@/%s", config.User, config.Password, config.Schema)
- db, err := gorm.Open("mysql", conf)
- if err != nil {
- log.Fatal(err)
- }
- defer userDB.Close()
- defer podcastDB.Close()
- defer episodeDB.Close()
- db.AutoMigrate(&models.User{}, &models.Podcast{}, &models.Episode{})
- db.Model(&models.Podcast{}).AddForeignKey("user_email", "users(user_name)", "CASCADE", "CASCADE")
- db.Model(&models.Episode{}).AddForeignKey("pod_id", "podcasts(podcast_id)", "CASCADE", "CASCADE")
Add Comment
Please, Sign In to add comment