Skip to content

Commit

Permalink
Add gorm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
egregius313 committed Jan 6, 2025
1 parent a911619 commit 5a4b1d0
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package test

import "gorm.io/gorm"

type User struct{}

// test querying an Association
func test_gorm_AssociationQuery(association *gorm.Association) {
association.Find(&User{}) // $ source
}

// test querying a ConnPool
func test_gorm_ConnPoolQuery(connPool gorm.ConnPool) {
rows, err := connPool.QueryContext(nil, "SELECT * FROM users") // $ source

if err != nil {
return
}

defer rows.Close()

userRow := connPool.QueryRowContext(nil, "SELECT * FROM users WHERE id = 1") // $ source

ignore(userRow)
}

// test querying a DB
func test_gorm_db(db *gorm.DB) {
db.Find(&User{}) // $ source

db.FindInBatches(&User{}, 10, nil) // $ source

db.FirstOrCreate(&User{}) // $ source

db.FirstOrInit(&User{}) // $ source

db.First(&User{}) // $ source

db.Last(&User{}) // $ source

db.Take(&User{}) // $ source

db.Scan(&User{}) // $ source

}

0 comments on commit 5a4b1d0

Please sign in to comment.