登录
首页 >  Golang >  Go问答

xorm,Sync 和 Sync2 函数之间的区别

来源:stackoverflow

时间:2024-02-10 18:15:23 301浏览 收藏

小伙伴们有没有觉得学习Golang很有意思?有意思就对了!今天就给大家带来《xorm,Sync 和 Sync2 函数之间的区别》,以下内容将会涉及到,若是在学习中对其中部分知识点有疑问,或许看了本文就能帮到你!

问题内容

xorm go 库有 2 个看起来相似的函数:

// Sync the new struct changes to database, this method will automatically add
// table, column, index, unique. but will not delete or change anything.
// If you change some field, you should change the database manually.
func (engine *Engine) Sync(beans ...interface{}) error 

// Sync2 synchronize structs to database tables
func (engine *Engine) Sync2(beans ...interface{}) error

(虽然 sync2()“文档”不包含它将添加列/索引等的解释,但实现似乎也这样做了)

这两个函数有什么区别,什么时候应该使用 sync,什么时候应该使用 sync2?


正确答案


看看https://gitea.com/xorm/xorm/src/commit/5fafa00043917e1253ebac95b5de29e2f08a569f/engine.go#L1115-L1128
(这是撰写本文时当前 master 分支的 HEAD)。

正如您所看到的,显然开发人员也注意到了这一点,并弃用了 Sync2,转而使用 Sync。 因此,简而言之,您根本不应该再使用 Sync2

今天关于《xorm,Sync 和 Sync2 函数之间的区别》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

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