1

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")) 
     } 
 } 

結果:

型の不一致; found : MyService.this.RowParser[Int] required: 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")) 
    } 
} 

パーサー コンビネーター メソッドをどのように実装すればよいですか?

4

0 に答える 0