2015-06-15 11 views
8

In Slick 2.1 ho avuto il codice qui sotto per eseguire uno sql-query da un file:Come utilizzare StaticQuery in Slick 3.0.0?

def fetchResult[T](sql: String)(implicit getResult: GetResult[T]): List[T] = { 
    val query = Q.queryNA[T](sql) 
    try { 
     Database.forDataSource(DB.getDataSource()) 
      .withSession { implicit session => query.list } 
    } 
    catch { 
     case e: Throwable => 
     throw new RunSqlException(s"Query $name execution error", e) 
    } 
} 

In 3.0.0 Slick si utilizza il metodo dbConfig.db.run per eseguire DBIOAction e ottenere un futuro di risultato . Ma non riesco a trovare un modo per trasformare il risultato di Q.queryNA (che è StaticQuery[Unit, R]) in DBIOAction. Esiste un modo del genere?

Per ora ho finito con chiamate obsolete. Aiutami a essere migliore!

def fetchResult[T](sql: String)(implicit getResult: GetResult[T]): Future[List[T]] = Future { 
    val query = Q.queryNA[T](sql) 
    try { 
     this.dbConfig.db.withSession { implicit session => query.list } 
    } 
    catch { 
     case e: Throwable => 
     throw new RunSqlException(s"Query $name execution error", e) 
    } 
} 
+0

C'è un problema https://github.com/slick/slick/issues/1161 sulla subj su GitHub. – sedovav

risposta

3

unica soluzione sono riuscito a trovare era un po 'hacker:

import slick.driver.HsqldbDriver.api._ 

def fetchResult[T](sql: String) = { 
    database.run(sqlu"""#$sql""") 
} 
Problemi correlati