Skip to content

Commit 90e7351

Browse files
committed
Menyimpan data ke DB
1 parent 28a2b76 commit 90e7351

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
56
"net/http"
67

@@ -24,6 +25,22 @@ func main() {
2425

2526
//fmt.Println("Database Berhasil Terhubung")
2627
db.AutoMigrate(&book.Book{})
28+
//CRUD
29+
30+
book := book.Book{}
31+
book.Title = "Cari Pengalaman"
32+
book.Price = 90000
33+
book.Discount = 10
34+
book.Rating = 5
35+
book.Description = "ini adalah buku yang sangat bagus dari zumardi rahman"
36+
37+
err = db.Create(&book).Error
38+
39+
if err != nil {
40+
fmt.Println("================================")
41+
fmt.Println("Error vreating book record")
42+
fmt.Println("================================")
43+
}
2744

2845
router := gin.Default()
2946

0 commit comments

Comments
 (0)