File tree Expand file tree Collapse file tree 1 file changed +27
-8
lines changed
Expand file tree Collapse file tree 1 file changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -27,21 +27,40 @@ func main() {
2727 db .AutoMigrate (& book.Book {})
2828 //CRUD
2929
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"
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"
3636
37- err = db .Create (& book ).Error
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+ // }
44+
45+ // var book book.Book
46+ var books []book.Book
47+
48+ //err = db.Debug().First(&book,2).Error //mengambil primary key
49+ // err = db.Debug().Find(&books).Error //mengambil bnyak data
50+ err = db .Debug ().Where ("rating = ?" , 5 ).Find (& books ).Error //mengambil wehere
3851
3952 if err != nil {
4053 fmt .Println ("================================" )
41- fmt .Println ("Error vreating book record" )
54+ fmt .Println ("Error Finding book record" )
4255 fmt .Println ("================================" )
4356 }
4457
58+ for _ , b := range books {
59+
60+ fmt .Println ("title:" , b .Title )
61+ fmt .Println ("book object" , b )
62+ }
63+
4564 router := gin .Default ()
4665
4766 v1 := router .Group ("/v1" )
You can’t perform that action at this time.
0 commit comments