- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 Postgres 的 RETURNING
与 ScalikeJDBC 一起使用(请参阅 https://github.com/scalikejdbc/scalikejdbc/issues/559 )
这如何与 where
子句一起使用。 returning(...)
是 UpdateSQLBuilder
的成员,而 where
返回 ConditionSQLBuilder
update(Post)
.set(sqls"${p.views}=${p.views}+${newViews}")
.where.eq(p.id,id)
.returning(p.id,p.lastUpdated, p.views) // does not work as it is not a member of ConditionSQLBuilder
最佳答案
正如您所说,返回
不是ConditionSQLBuilder
的成员。但是,您可以在 where
子句之后使用 append
方法,因为它是在 ConditionSQLBuilder
上定义的:
update(Post)
.set(sqls"${p.views} = ${p.views} + ${newViews}")
.where.eq(p.id, id)
.append(sqls"returning ${p.id}, ${p.lastUpdated}, ${p.views}"
并且,如果您将使用构建器将返回列映射到对象中,如下所示:
val postOpt = withSQL(builder).map(Post(p)).single().apply()
那么您必须在 SQLSyntax
中使用 ${p.result.columnName}
而不是 ${p.columnName}
,您可以使用作为参数传递给 append
方法。要映射所有列,只需使用 ${p.result.*}
。
关于scala - 如何将 ScalikeJDBC 的 returned() 与 where 子句一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49069348/
谁能给我一个示例,说明如何在具有动态值的 scalikejdbc 中使用 like 子句。我使用了以下查询,但没有用 sql"select * from tables_list where lowe
我正在尝试批量插入 100 个表(我听说这是与 mySQL 一起使用的最佳大小),我使用 scala 2.10.4 和 sbt 0.13.6,我使用的 jdbc 框架是 scalikejdbc 和 H
我正在尝试使用 scalikeJDBC 连接到 postgres 我有以下错误信息: An exception or error caused a run to abort: No suitable
我使用 scalikejdbc 2.0.1 和 playframework 2.3。我按照一对多 http://scalikejdbc.org/documentation/one-to-x.html
我正在玩 ScalikeJdbc 库。我想从 PostgreSQL 数据库中检索数据。我得到的错误对我来说很奇怪。即使我手动配置 CP: val poolSettings = new Connecti
我有一个模型,如下所示。 case class House ( id: Int, name: String, cityId: Int, leaseInterval: I
我尝试使用 ScalikeJDBC 访问 PostgreSQL 9.4 中的数组。动态链接库: create table itab ( code varchar primary key
据我从 Scalikejdbc 的文档中了解到,如果我想要进行交易,我需要通过 session 。像这样: class FooBarService { val fooDao = new F
所以我有这个 sql(更大查询的一部分): from Person p left join ForeignCredentials fc on fc.person_id = p.id and fc.ty
我正在尝试将 Postgres 的 RETURNING 与 ScalikeJDBC 一起使用(请参阅 https://github.com/scalikejdbc/scalikejdbc/issues
尝试使用 ScalikeJDBC 和 SQLite。根据提供的示例编写一个简单的代码: import scalikejdbc._, SQLInterpolation._ object Test ext
为了避免 DRY,我尝试创建一个带有变量列名称和数据的 sql INSERT 语句,以通过 ScalikeJDBC 的 sql 插值填充这些列: case class MySQLInsertMessa
我是一名优秀的程序员,十分优秀!