-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgorm.go
More file actions
36 lines (31 loc) · 826 Bytes
/
gorm.go
File metadata and controls
36 lines (31 loc) · 826 Bytes
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
35
36
package main
import (
"fmt"
"gorm.io/gorm"
"workplace/internal/database"
"workplace/internal/injector"
)
func main() {
container := injector.GetContainer()
err := container.Invoke(func(db *gorm.DB, repository database.ProductRepository) {
database.Migrate(db)
products, err := repository.GetProductsLikeName("computer2%")
if err != nil {
panic(err)
}
for _, product := range products {
creator := "none"
if product.Creator != nil {
creator = product.Creator.Name
}
fmt.Println(fmt.Sprintf("id: %d, name: %s, user: %s",
product.ID,
product.Name,
creator,
))
}
})
if err != nil {
panic(err)
}
}