登录
首页 >  Golang >  Go问答

我可以用什么来代替 DB.Where

来源:stackoverflow

时间:2024-04-30 11:36:31 103浏览 收藏

大家好,我们又见面了啊~本文《我可以用什么来代替 DB.Where》的内容中将会涉及到等等。如果你正在学习Golang相关知识,欢迎关注我,以后会给大家带来更多Golang相关文章,希望我们能一起进步!下面就开始本文的正式内容~

问题内容

在 gorm 中,我们可以使用 db.where 从数据库中检查用户的数据以进行身份​​验证。但我必须使用 go fiber,所以我可以使用什么来代替 db.where 来检查用户是否存在于数据库中。

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

正确答案


嗯,根据你的问题,gorm 既作为数据库也作为框架工作。

你可以使用go fiber作为框架,但是如果你想使用数据库,你不能使用来自fibre的数据库,而是必须使用一个数据库,你可以从中找到数据库中数据的集合。

例如,您将 mongodb 与 gofiber 一起使用,因此它将使用 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

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>