带有 CloudSQL 的 Golang Gorm db.raw 更新 SQL 查询不起作用?

标签 go google-cloud-sql go-gorm

我有这个 SQL 查询,它单独运行良好,受影响的 2 行绝对没问题

update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > 0

但是当我在 golang 中尝试 gorm 的执行变体语句时,即

err := h.db.Raw("update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > ? ", 0).Error

numRecsToProcess := h.db.Raw("update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > ? ", 0).RowsAffected

这些更新语句都不会影响基础数据库中的任何更改。 Gorm 使用功能中是否缺少某些内容?

最佳答案

尝试使用 h.db.Exec 而不是 h.db.Raw

关于带有 CloudSQL 的 Golang Gorm db.raw 更新 SQL 查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39239543/

相关文章:

go - 如何永久删除 GORM 中的关联

database - 在 gorm orm 上为 golang 中的微服务创建顶级包

go - 如何从另一个函数返回函数?

go - GO中的第二次scanf跳转扫描

go - 如何使用 GORM (Go) 进行级联操作

google-cloud-platform - 从 Google Dataflow 连接到 CloudSql

c - 类型安全与松散类型 - GO 与 C

php - Google 计算引擎 + Cloud SQL + Cloud DNS + Google Domains - IP 已更改

python - 无法在谷歌应用引擎中使用 mysql - 加载 MySQLdb 模块时出错 : No module named _mysql. 我正在使用 cloudSQL

database - 这种数据访问模式是线程安全的吗?