From 2109abdae69a5e38c4bbbd46d1cb4939893c244d Mon Sep 17 00:00:00 2001 From: "wfhtqp@gmail.com" Date: Fri, 6 Dec 2024 12:56:30 +0800 Subject: [PATCH] bug: first table error --- go.mod | 14 +++++++------- main_test.go | 13 +++++++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index f194634f..823961aa 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.23.3 require ( gorm.io/driver/mysql v1.5.7 - gorm.io/driver/postgres v1.5.10 + gorm.io/driver/postgres v1.5.11 gorm.io/driver/sqlite v1.5.6 gorm.io/driver/sqlserver v1.5.4 gorm.io/gen v0.3.26 @@ -26,13 +26,13 @@ require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/mattn/go-sqlite3 v1.14.24 // indirect - github.com/microsoft/go-mssqldb v1.7.2 // indirect - golang.org/x/crypto v0.29.0 // indirect + github.com/microsoft/go-mssqldb v1.8.0 // indirect + golang.org/x/crypto v0.30.0 // indirect golang.org/x/mod v0.22.0 // indirect - golang.org/x/sync v0.9.0 // indirect - golang.org/x/sys v0.27.0 // indirect - golang.org/x/text v0.20.0 // indirect - golang.org/x/tools v0.27.0 // indirect + golang.org/x/sync v0.10.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect + golang.org/x/tools v0.28.0 // indirect gorm.io/datatypes v1.2.4 // indirect gorm.io/hints v1.1.2 // indirect gorm.io/plugin/dbresolver v1.5.3 // indirect diff --git a/main_test.go b/main_test.go index 60a388f7..3fbac34c 100644 --- a/main_test.go +++ b/main_test.go @@ -9,12 +9,21 @@ import ( // TEST_DRIVERS: sqlite, mysql, postgres, sqlserver func TestGORM(t *testing.T) { - user := User{Name: "jinzhu"} + user := User{Name: "jinzhu", Age: 5} + toy := Toy{Name: "jinzhu", OwnerID: "test"} DB.Create(&user) + DB.Create(&toy) var result User - if err := DB.First(&result, user.ID).Error; err != nil { + DB = DB.Where("name = ?", "jinzhu") + + if err := DB.First(&result, "age = ?", 5).Error; err != nil { + t.Errorf("Failed, got error: %v", err) + } + var ttoy Toy + + if err := DB.First(&ttoy, "owner_id = ?", "test").Error; err != nil { t.Errorf("Failed, got error: %v", err) } }