英文:
xorm , difference between Sync and Sync2 functions
问题
xorm go库有两个看起来相似的函数:
// 将新的结构更改同步到数据库,此方法将自动添加表、列、索引和唯一约束,但不会删除或更改任何内容。
// 如果更改了某些字段,应手动更改数据库。
func (engine *Engine) Sync(beans ...interface{}) error
// 将结构同步到数据库表
func (engine *Engine) Sync2(beans ...interface{}) error
(尽管Sync2()的“文档”中没有包含它将添加列/索引等的解释,但实现似乎也会执行这些操作)
这两个函数之间有什么区别?在什么情况下应该使用Sync,什么情况下应该使用Sync2?
英文:
The xorm go library has 2 function that appear similar:
// 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
(While the Sync2() "docs" doesn't contain the explanation that it will add columns/indexes etc, the implementation does seem to do that too)
What is the difference between these two functions, and when should you use Sync and when should you use Sync2 ?
答案1
得分: 0
请看 https://gitea.com/xorm/xorm/src/commit/5fafa00043917e1253ebac95b5de29e2f08a569f/engine.go#L1115-L1128(这是我写作时当前“master”分支的“HEAD”)。
正如你在那里看到的,显然开发人员也注意到了这一点,并且已经弃用了Sync2
,而推荐使用Sync
。所以,简而言之,你根本不应该再使用Sync2
了。
英文:
Have a look at https://gitea.com/xorm/xorm/src/commit/5fafa00043917e1253ebac95b5de29e2f08a569f/engine.go#L1115-L1128
(which is the HEAD
of the current master
branch at the time of writing).
As you can see there, apparently the developers noticed that as well, and deprecated Sync2
in favor of Sync
.
So, in short, you simply shouldn't use Sync2
at all anymore.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论