从选择查询到嵌套案例类的Scalike映射结果

时间:2018-10-04 13:29:55

标签: mysql scala case-class scalikejdbc

嗨,我正在尝试将以下选择查询的结果映射到嵌套的案例类。我正在使用scalike 3.3,到目前为止,我已经有了以下代码,但是它不起作用:

 val dashboardDetails: List[MainReportFields] =
SQL("select " +
  "d.dashboard_id, " +
  "d.dashboard_name, " +
  "rpt.cube_id, " +
 "rpt.report_id," +
 "rpt.query_builder_json," +
 "rpt.action," +
  "g.column_id,g.sequence," +
 "sc.selected_column_id," +
  "sc.column_name," +
  "sc.sequence," +
  "fd.formatting_id," +
 "fd.selected_column_id," +
 "fd.format_id," +
   "fd.type " +
  "from ReportingMetabase.dashboard_details d " +
  "inner join ReportingMetabase.report_details rpt " +
   "on d.dashboard_id = rpt.dashboard_id " +
    "inner join ReportingMetabase.group_by_details g " +
   "on rpt.report_id = g.report_id " +
  "inner join ReportingMetabase.selected_columns sc " +
   "on rpt.report_id = sc.report_id " +
  "inner join ReportingMetabase.formatting_details fd " +
   "on sc.selected_column_id = fd.selected_column_id " +
    "inner join ReportingMetabase.format_type_details ftd " +
    "on fd.format_id = ftd.format_id")
    .map(_.get[MainReportFields](1)).list() apply() 
    // read results into main case class

案例类如下:

 case class ReportsFields(
              reportid: Option[Long],
              reportName: String,
              selectedColumns: List[SelectedColumns],
              queryBuilderString: String,
              havingjson: String,
              groupByFields: List[GroupByFields],
              orderByFileds: List[OrderByFileds]
            )

 case class MainReportFields(
                 cubeid: Long,
                 dashboardId: Long,
                 dashboardName: String,
                 reports: List[ReportsFields]
               )

我也在这里尝试了示例:http://scalikejdbc.org/documentation/one-to-x.html

但是它不适用于scalikejdbc 3.3

0 个答案:

没有答案