2013-01-15 2 views
0
다음 DB 스크립트와

:이 방법스칼라 Anorm 선택 쿼리

def getTask(hash: Int): String = DB.withConnection { implicit c => 
    val result = SQL(
     """ 
     select count(*) as url from HashToUrl where hash={hash} 
     """ 
    ).apply().head 
    val url = result[String]("url") 
    url 
} 

답변

1

에 대한

[NoSuchElementException: key not found: hash]

... :

# Tasks schema 

# --- !Ups 

CREATE TABLE HashToUrl (
    hash integer, 
    url varchar(255) 
); 

# --- !Downs 

DROP TABLE HashToUrl; 

... 나는이 오류가 왜 코드에 해시 변수를 형식 문자열로 대체하는 항목이 없습니다. 여기

당신이 무엇을 볼 수 있도록 몇 가지 아주 간단한 anorm의 예는 다음과 같습니다

https://github.com/dustingetz/orm-deep-dive/blob/master/app/models/Environment.scala