package main import ( "bindbox-game/configs" "bindbox-game/internal/repository/mysql" "bindbox-game/internal/repository/mysql/model" "flag" "fmt" "strconv" ) func main() { // flag.StringVar(&env, "env", "dev", "env") flag.Parse() configs.Init() dbRepo, err := mysql.New() if err != nil { panic(err) } db := dbRepo.GetDbR() userID := int64(9072) // 1. Simulate ListInventoryWithProduct Query (No Keyword) var totalNoKeyword int64 db.Table(model.TableNameUserInventory). Where("user_id = ?", userID). Count(&totalNoKeyword) fmt.Printf("Scenario 1 (No Keyword) Total: %d\n", totalNoKeyword) // 2. Simulate With Keyword (Empty string? space?) // If the frontend sends " " (space), let's see. keyword := " " var totalWithSpace int64 db.Table(model.TableNameUserInventory). Joins("LEFT JOIN products p ON p.id = user_inventory.product_id"). Where("user_inventory.user_id = ?", userID). Where("p.name LIKE ?", "%"+keyword+"%"). Count(&totalWithSpace) fmt.Printf("Scenario 2 (Keyword ' ') Total: %d\n", totalWithSpace) // 3. Simulate specific Keyword '小米' keyword2 := "小米" var totalXiaomi int64 db.Table(model.TableNameUserInventory). Joins("LEFT JOIN products p ON p.id = user_inventory.product_id"). Where("user_inventory.user_id = ?", userID). Where("p.name LIKE ?", "%"+keyword2+"%"). Count(&totalXiaomi) fmt.Printf("Scenario 3 (Keyword '小米') Total: %d\n", totalXiaomi) // 4. Simulate Numeric Keyword "29072" (Searching by ID) keyword3 := "29072" numKeyword, _ := strconv.ParseInt(keyword3, 10, 64) var totalNumeric int64 db.Table(model.TableNameUserInventory). Joins("LEFT JOIN products p ON p.id = user_inventory.product_id"). Where("user_inventory.user_id = ?", userID). Where( db.Where("p.name LIKE ?", "%"+keyword3+"%"). Or("user_inventory.id = ?", numKeyword). Or("user_inventory.order_id = ?", numKeyword), ). Count(&totalNumeric) fmt.Printf("Scenario 4 (Numeric Keyword '%s') Total: %d\n", keyword3, totalNumeric) // 5. Check if there are soft deletes? // Check if `deleted_at` column exists var cols []string db.Raw("SHOW COLUMNS FROM user_inventory").Pluck("Field", &cols) fmt.Printf("Columns: %v\n", cols) }