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.

Slickで複数カラムのOrderByしたい

Posted at

SQL

select * from "hoge" order by "a_id", "b_id"

みたいなことしたかった。

Slick

単一のカラムの時はこう

hoges.sortBy(_.aID.asc)

最初は二つ並べればいいかと思ったんですが、明らかにダサいので別の方法を探しました。

hoges.sortBy(_.aID.asc).sortBy(_.bID.asc)

で、実はOrderはタプルにするとまとめられるらしいです。

hoges.sortBy(x => (x.aID.asc, x.bID.asc))

参考: http://slick.lightbend.com/doc/3.1.0/sql-to-slick.html#order-by

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?