diff options
Diffstat (limited to 'models/database.go')
| -rw-r--r-- | models/database.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/models/database.go b/models/database.go index 2daaa1e..ffc8a47 100644 --- a/models/database.go +++ b/models/database.go @@ -1,18 +1,28 @@ package models import ( + "os" "time" "gorm.io/driver/sqlite" "gorm.io/gorm" ) +type List struct { + Name string `gorm:"primaryKey"` + Password []byte + CreatedAt time.Time + UpdatedAt time.Time + Entries []Entry +} + type Entry struct { ID uint `gorm:"primaryKey"` Text string Checked bool CreatedAt time.Time UpdatedAt time.Time + ListName string } var DB *gorm.DB @@ -24,7 +34,17 @@ func ConnectDatabase() { panic("Failed to connect to database!") } + db.AutoMigrate(&List{}) db.AutoMigrate(&Entry{}) DB = db } + +func BasePath() string { + basePath := os.Getenv("BASE_PATH") + if basePath == "" { + basePath = "/" + } + + return basePath +} |