I'm trying to trying to determine existence of a value in the database, so I choose to use Select 1 From table
, but how can I get the data?
I want to check two people are buddies, and here are my models
type Buddy struct {
ID uint64 `gorm:"primarykey"`
UserID uint32
BuddyID uint32
}
this is the gorm sql I've tried
// select 1 from buddies where user_id=? and buddy_id=?
type Result struct {
Exist uint32
}
exist := &Result{}
orm.DB.Debug().Table("buddies").Raw("SELECT 1 as exist FROM buddies WHERE user_id = ? and buddy_id = ?", userID, buddyID).Scan(exist)
but I didn't get anything in exist.Exist