Last active
April 13, 2016 09:16
-
-
Save tango238/7630815016c86aaa412d6217644f48c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[info] Compiling 1 Scala source to /Users/Go/Works/myproject/target/scala-2.11/classes... | |
[error] /Users/Go/Works/myproject/app/repositories/UserRepository.scala:15: type mismatch; | |
[error] found : slick.profile.SqlAction[Option[models.Tables.UserRow],slick.dbio.NoStream,slick.dbio.Effect.Read] | |
[error] required: slick.dbio.DBIOAction[Option[models.Tables.User],slick.dbio.NoStream,Nothing] | |
[error] def findById(id: Long): Future[Option[User]] = db.run(User.filter(_.id === id.bind).result.headOption) | |
[error] ^ | |
[[syntax trees at end of typer]] // UserRepository.scala | |
package repositories { | |
import javax.inject.{Inject, Singleton}; | |
import models.Tables._; | |
import play.api.db.slick._; | |
import scala.concurrent.Future; | |
import slick.driver.JdbcProfile; | |
import slick.driver.MySQLDriver.api._; | |
@javax.inject.Singleton class UserRepository extends AnyRef with play.api.db.slick.HasDatabaseConfigProvider[slick.driver.JdbcProfile] { | |
<paramaccessor> private[this] val dbConfigProvider: play.api.db.slick.DatabaseConfigProvider = _; | |
<stable> <accessor> <paramaccessor> def dbConfigProvider: play.api.db.slick.DatabaseConfigProvider = UserRepository.this.dbConfigProvider; | |
@javax.inject.Inject def <init>(dbConfigProvider: play.api.db.slick.DatabaseConfigProvider): repositories.UserRepository = { | |
UserRepository.super.<init>(); | |
() | |
}; | |
def findById(id: Long): scala.concurrent.Future[Option[models.Tables.User]] = UserRepository.this.db.run[R](User.filter(((x$1: models.Tables.User) => x$1.id.$eq$eq$eq(id.bind))).result.headOption) | |
} | |
} | |
[error] one error found | |
[error] (compile:compileIncremental) Compilation failed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models | |
// AUTO-GENERATED Slick data model | |
/** Stand-alone Slick data model for immediate use */ | |
object Tables extends { | |
val profile = slick.driver.MySQLDriver | |
} with Tables | |
/** Slick data model trait for extension, choice of backend or usage in the cake pattern. (Make sure to initialize this late.) */ | |
trait Tables { | |
val profile: slick.driver.JdbcProfile | |
import profile.api._ | |
import com.github.tototoshi.slick.MySQLJodaSupport._ | |
import org.joda.time.DateTime | |
import slick.model.ForeignKeyAction | |
// NOTE: GetResult mappers for plain SQL are only generated for tables where Slick knows how to map the types of all columns. | |
import slick.jdbc.{GetResult => GR} | |
/** DDL for all tables. Call .create to execute. */ | |
lazy val schema: profile.SchemaDescription = User.schema | |
@deprecated("Use .schema instead of .ddl", "3.0") | |
def ddl = schema | |
/** Entity class storing rows of table User | |
* @param id Database column id SqlType(BIGINT UNSIGNED), AutoInc, PrimaryKey | |
* @param name Database column name SqlType(VARCHAR), Length(255,true), Default(None) | |
* @param email Database column email SqlType(VARCHAR), Length(255,true), Default(None) | |
* @param password Database column password SqlType(VARCHAR), Length(255,true), Default(None) | |
* @param created Database column created SqlType(DATETIME), Default(None) | |
* @param updated Database column updated SqlType(DATETIME), Default(None) */ | |
case class UserRow(id: Long, name: Option[String] = None, email: Option[String] = None, password: Option[String] = None, created: Option[DateTime] = None, updated: Option[DateTime] = None) | |
/** GetResult implicit for fetching UserRow objects using plain SQL queries */ | |
implicit def GetResultUserRow(implicit e0: GR[Long], e1: GR[Option[String]], e2: GR[Option[DateTime]]): GR[UserRow] = GR{ | |
prs => import prs._ | |
UserRow.tupled((<<[Long], <<?[String], <<?[String], <<?[String], <<?[DateTime], <<?[DateTime])) | |
} | |
/** Table description of table User. Objects of this class serve as prototypes for rows in queries. */ | |
class User(_tableTag: Tag) extends Table[UserRow](_tableTag, "User") { | |
def * = (id, name, email, password, created, updated) <> (UserRow.tupled, UserRow.unapply) | |
/** Maps whole row to an option. Useful for outer joins. */ | |
def ? = (Rep.Some(id), name, email, password, created, updated).shaped.<>({r=>import r._; _1.map(_=> UserRow.tupled((_1.get, _2, _3, _4, _5, _6)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported.")) | |
/** Database column id SqlType(BIGINT UNSIGNED), AutoInc, PrimaryKey */ | |
val id: Rep[Long] = column[Long]("id", O.AutoInc, O.PrimaryKey) | |
/** Database column name SqlType(VARCHAR), Length(255,true), Default(None) */ | |
val name: Rep[Option[String]] = column[Option[String]]("name", O.Length(255,varying=true), O.Default(None)) | |
/** Database column email SqlType(VARCHAR), Length(255,true), Default(None) */ | |
val email: Rep[Option[String]] = column[Option[String]]("email", O.Length(255,varying=true), O.Default(None)) | |
/** Database column password SqlType(VARCHAR), Length(255,true), Default(None) */ | |
val password: Rep[Option[String]] = column[Option[String]]("password", O.Length(255,varying=true), O.Default(None)) | |
/** Database column created SqlType(DATETIME), Default(None) */ | |
val created: Rep[Option[DateTime]] = column[Option[DateTime]]("created", O.Default(None)) | |
/** Database column updated SqlType(DATETIME), Default(None) */ | |
val updated: Rep[Option[DateTime]] = column[Option[DateTime]]("updated", O.Default(None)) | |
} | |
/** Collection-like TableQuery object for table User */ | |
lazy val User = new TableQuery(tag => new User(tag)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package repositories | |
import javax.inject.{Inject, Singleton} | |
import models.Tables._ | |
import play.api.db.slick._ | |
import scala.concurrent.Future | |
import slick.driver.JdbcProfile | |
import slick.driver.MySQLDriver.api._ | |
@Singleton | |
class UserRepository @Inject()(val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] { | |
def findById(id: Long): Future[Option[User]] = db.run(User.filter(_.id === id.bind).result.headOption) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment