blob: 2daaa1ed3a3074fc13aad2e5e201b9a76f221cb2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package models
import (
"time"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type Entry struct {
ID uint `gorm:"primaryKey"`
Text string
Checked bool
CreatedAt time.Time
UpdatedAt time.Time
}
var DB *gorm.DB
func ConnectDatabase() {
db, err := gorm.Open(sqlite.Open("shopping_list.db"), &gorm.Config{})
if err != nil {
panic("Failed to connect to database!")
}
db.AutoMigrate(&Entry{})
DB = db
}
|