Skip to content

Commit faee391

Browse files
committed
fix: add missing Count method to CreateInterface (closes #7580)
1 parent 688e8ea commit faee391

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

clause/set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Assignment struct {
1111

1212
// Assigner assignments provider interface
1313
type Assigner interface {
14-
Assignments() []Assignment
14+
Assignments() []Assignment
1515
}
1616

1717
func (set Set) Name() string {

generics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type CreateInterface[T any] interface {
5757
Delete(ctx context.Context) (rowsAffected int, err error)
5858
Update(ctx context.Context, name string, value any) (rowsAffected int, err error)
5959
Updates(ctx context.Context, t T) (rowsAffected int, err error)
60+
Count(ctx context.Context, column string) (result int64, err error)
6061

6162
Table(name string, args ...interface{}) CreateInterface[T]
6263
Create(ctx context.Context, r *T) error

tests/generics_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,3 +936,43 @@ func TestGenericsScanUUID(t *testing.T) {
936936
t.Fatalf("wrong uuid scanned")
937937
}
938938
}
939+
940+
func TestGenericsCount(t *testing.T) {
941+
ctx := context.Background()
942+
943+
// Just test that the API can be called
944+
_, err := gorm.G[User](DB).Count(ctx, "*")
945+
if err != nil {
946+
t.Fatalf("Count failed: %v", err)
947+
}
948+
}
949+
950+
func TestGenericsUpdate(t *testing.T) {
951+
ctx := context.Background()
952+
953+
// Just test that the API can be called
954+
_, err := gorm.G[User](DB).Where("id = ?", 1).Update(ctx, "name", "test")
955+
if err != nil {
956+
t.Fatalf("Update failed: %v", err)
957+
}
958+
}
959+
960+
func TestGenericsUpdates(t *testing.T) {
961+
ctx := context.Background()
962+
963+
// Just test that the API can be called
964+
_, err := gorm.G[User](DB).Where("id = ?", 1).Updates(ctx, User{Name: "test"})
965+
if err != nil {
966+
t.Fatalf("Updates failed: %v", err)
967+
}
968+
}
969+
970+
func TestGenericsDeleteAPI(t *testing.T) {
971+
ctx := context.Background()
972+
973+
// Just test that the API can be called
974+
_, err := gorm.G[User](DB).Where("id = ?", 1).Delete(ctx)
975+
if err != nil {
976+
t.Fatalf("Delete failed: %v", err)
977+
}
978+
}

0 commit comments

Comments
 (0)