如何扩展Anorm的解析器组合器?

时间:2012-02-22 17:59:33

标签: parsing scala playframework anorm

如何扩展Anorm的解析器组合器并使用扩展 我的应用程序? 我想创建类似于SqlParser.get,SqlParser.int的方法, SqlParser.str等,并期望扩展SqlParser特征。但当 我扩展了SqlParser,当我尝试使用时出现编译错误 现有的解析器组合方法:

 trait MyService extends SqlParser { 
     def shoesize(id: String): Int = { 
         SQL("select shoesize from person where id = {id}")
         .on("id" -> id).as (int ("shoesize")) 
     } 
 } 

结果:

  

类型不匹配;发现:MyService.this.RowParser [Int]要求:   play.db.anorm.SqlParser.Parser [Int]应用程序中发生错误   涉及默认参数。

但这会编译:

trait MyService  { 
    import play.db.anorm.SqlParser._ 
    def shoesize(id: String): Int = { 
        SQL("select shoesize from person where id = {id}").on("id" -> id)
        .as (int ("shoesize")) 
    } 
} 

我应该如何实现我的解析器组合方法?

0 个答案:

没有答案