3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Scala Slickでin, count

Posted at

よく忘れるのでメモ。slickのバージョンは1.0.1

in

サンプル
// typesを引数で貰ったとして
val query = (for {
  log <- Query(XXXLogTable) if (log.type inSet (types.flatMap(t => Seq(t.code))))
} yield (log.id)).list

count

count

サンプル
val c = (for {
  log <- Query(XXXLogTable) if (log.type inSet (types.flatMap(t => Seq(t.code))))
} yield(log.id.count)).first
生成されたSQL
select count(x2.`id`) from `xxx_log` x2 where x2.`type` in (0, 1)

ただ、

method count in class ColumnExtensionMethods is deprecated: Use Query.count instead

とのことなので、やってみる。

Query.length

サンプル
val q = Query(XXXLogTable).where(log.type inSet (types.flatMap(t => Seq(t.code))))
                          .length
q.run
生成されたSQL
select x2.x3 from (select count(1) as x3 from (select x4.`id`, x4.`xxx`, x4.`yyy` from `xxx_log` x4 where x4.`type` in (0, 1)) x5) x2

SQLが。。
ひとまずcountを使うとして、lengthの使い方は再調査が必要。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?