user := User{Name: "Alice", Age: 25} db.NewRecord(user) // true db.Create(&user) db.NewRecord(user) // false
var user User db.Where("name = ?", "Alice").First(&user) db.NewRecord(user) // falseIn the above example, we retrieve the first record with the name "Alice" from the User table and store it in the user variable. Then we check if this user struct instance is a new record or not using NewRecord. Since it has been retrieved from the database, it is not a new record and NewRecord returns false. Overall, Github.com/jinzhu/gorm is a popular package library for Go programming language that provides an easy-to-use ORM layer on top of your SQL database. It simplifies database access and management by providing a clean and concise API that abstracts away the underlying database operations.