-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
34 lines (28 loc) · 614 Bytes
/
main.go
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
31
32
33
34
package main
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
// User simple test gorm
type User struct {
gorm.Model
Username string
Password string
Email string
}
func main() {
db, err := gorm.Open("sqlite3", "test.db")
if err != nil {
panic("failed to connect to database")
}
defer db.Close()
db.AutoMigrate(&User{})
db.Create(&User{Username: "test", Password: "test", Email: "[email protected]"})
var user User
db.First(&user, 1)
db.First(&user, "username = ?", "test")
db.Model(&user).Update("Username", "test")
fmt.Println(user)
db.Delete(&user)
}