Skip to content

Instantly share code, notes, and snippets.

@tsukaby
Last active December 4, 2015 09:27
Show Gist options
  • Save tsukaby/283c5698c73ae222de29 to your computer and use it in GitHub Desktop.
Save tsukaby/283c5698c73ae222de29 to your computer and use it in GitHub Desktop.
Scalikejdbcの共通化
// http://scalikejdbc.org/documentation/query-dsl.html
val o = Order.syntax("o")
val orders = withSQL {
  select
    .from(Order as o)
    .where
    .eq(o.productId, 123)
    .and
    .isNotNull(o.orderedAt)
  }.map(Order(o)).list.apply()

Orderテーブル、Itemテーブル、Productテーブルがあるとして、全てのテーブルはproductId列を持っている。 ここで

def conditionToSql(condition: Condition, syntax: ?): SQLSyntax = {
  sqls.eq(syntax.productId, condition.productId)
}

みたいな共通利用できる関数を作ってCondition objectを柔軟にSQLSyntaxに変えたいけど、syntax: ?の部分の型をどうすればよいのか・・・

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment