SocialDragon/database/main.go
Andreas Mieke 0a69d4a9f2 Initial commit
Implemented getters for:
    * Snapchat
    * Twitter
    * Instagram

Also implemented config and database modules.
2017-01-17 23:39:59 +01:00

68 lines
1 KiB
Go

package database
import (
"log"
"time"
"git.1750studios.com/AniNite/SocialDragon/config"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
)
type Service uint
const (
Snapchat Service = iota
Twitter
Instagram
)
type State uint
const (
Inbox State = iota
Approved
Rejected
)
type Item struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
UserID uint `sql:"index"`
Service Service
State State
IsVideo bool
Path string
OriginalID string
}
type User struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
Name string
DisplayName string
Service Service
Blocked bool
}
var Db *gorm.DB
func InitDb() {
var err error
Db, err = gorm.Open("postgres", config.C.DatabaseConnection)
if err != nil {
log.Fatalf("Database error: %+v", err)
}
Db.LogMode(false)
Db.SingularTable(true)
Db.Model(&Item{}).AddForeignKey("user_id", "user(id)", "RESTRICT", "RESTRICT")
Db.AutoMigrate(&Item{}, &User{})
}