Skip to content

Instantly share code, notes, and snippets.

@masahiko-nitanda
Created August 20, 2023 11:50
Show Gist options
  • Save masahiko-nitanda/01a03a1cf72be94c228273b83f995497 to your computer and use it in GitHub Desktop.
Save masahiko-nitanda/01a03a1cf72be94c228273b83f995497 to your computer and use it in GitHub Desktop.
This Gist is a Go code snippet using GORM to query for a user with a specific name (in this case, "Alice"). The User struct embeds gorm.Model, allowing for automatic management of created_at, updated_at, and deleted_at fields in CRUD operations.
type User struct {
gorm.Model
Name string
}
db.Model(&User{}).Where("name = ?", "Alice").First(&user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment