你可以使用DB.Where的替代方法是什么?

huangapple go评论68阅读模式
英文:

What can I use in place of DB.Where

问题

在Go Fiber中,你可以使用DB.Where来检查数据库中用户的数据进行身份验证。但是,你需要使用Go Fiber,那么在替代DB.Where来检查用户是否存在于数据库中时,你可以使用什么呢?

var user models.User
database.DB.Where("id = ?", claims.Issuer).Find(&user)

在上面的代码中,我们使用Find方法来替代DB.Where,并将查询结果存储在user变量中。这样,你就可以检查用户是否存在于数据库中了。

英文:

In Gorm we can use DB.Where to check the data of the user from the database for authentication. But I have to use Go Fiber so what can I use in place of DB.Where to check if the user is present in the database.

var user models.User    
database.DB.Where("id = ?", claims.Issuer).(&user)

答案1

得分: 0

嗯,根据你的问题,gorm既可以作为数据库,也可以作为框架使用。

你可以使用Go Fiber作为框架,但如果你想使用数据库,就不能直接从Fiber中使用数据库,而是需要使用一个可以在数据库中找到数据集合的数据库。

例如,如果你正在使用GoFiber和MongoDB,那么它将使用DB.Collection.FindOne()方法。

在gorm中,使用Db.Where来查找数据库集合。

英文:

Well, as per your question gorm is working as a database also as a framework.

you can use go fiber as a framework but if you want to use the database you cannot use the database from fiber instead you have to use a database from which you can find the collection of the data in the database.

For example, you are using MongoDB with GoFiber so it will use the method of DB.Collection.FindOne()

In form Db.Where is used to find the database collection

答案2

得分: 0

好的,以下是翻译好的内容:

嗯,根据你的问题,gorm既可以作为数据库,也可以作为框架使用。

你可以使用Go Fiber作为框架,但如果你想使用数据库,就不能直接从Fiber中使用数据库,而是需要使用一个可以在数据库中找到数据集合的数据库。

例如,如果你正在使用GoFiber和MongoDB,那么它将使用DB.Collection.FindOne()方法。

在表单中,使用Db.Where来查找数据库集合。

英文:
Well, as per your question gorm is working as a database also as a framework.

you can use go fiber as a framework but if you want to use the database you cannot use the database from fiber instead you have to use a database from which you can find the collection of the data in the database.

For example, you are using MongoDB with GoFiber so it will use the method of DB.Collection.FindOne()

In form Db.Where is used to find the database collection

huangapple
  • 本文由 发表于 2021年10月11日 13:25:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/69521392.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定