灵活的PostgreSQL集成
我是scala新手,我正在尝试将PostgreSQL数据库集成到用scala编写的Lagom应用程序中。我正在尝试使用Lagom的持久化API。Lagom内置了对slick的支持 我的表有3个字段,id类型为int,name类型为string,data类型为jsonb 因为Slick不支持json格式,所以我尝试使用它 下面是我的实现 我的自定义配置文件类灵活的PostgreSQL集成,postgresql,scala,slick,lagom,slick-pg,Postgresql,Scala,Slick,Lagom,Slick Pg,我是scala新手,我正在尝试将PostgreSQL数据库集成到用scala编写的Lagom应用程序中。我正在尝试使用Lagom的持久化API。Lagom内置了对slick的支持 我的表有3个字段,id类型为int,name类型为string,data类型为jsonb 因为Slick不支持json格式,所以我尝试使用它 下面是我的实现 我的自定义配置文件类 import com.github.tminglei.slickpg.{ExPostgresProfile, PgPlayJsonSuppo
import com.github.tminglei.slickpg.{ExPostgresProfile, PgPlayJsonSupport}
import play.api.libs.json.JsValue
import slick.basic.Capability
import slick.jdbc.{JdbcCapabilities, PostgresProfile}
trait CustomPostgresProfile extends ExPostgresProfile with PgPlayJsonSupport {
def pgjson = "jsonb"
override protected def computeCapabilities: Set[Capability] =
super.computeCapabilities + JdbcCapabilities.insertOrUpdate
override val api = PostgresJsonSupportAPI
object PostgresJsonSupportAPI extends API with JsonImplicits {}
}
object CustomPostgresProfile extends PostgresProfile
我的表格定义
import com.custom.persistence.profile.CustomPostgresProfile.api._
import play.api.libs.json._
case class CustomDataEntity(id:int,name: String, data: JsValue)
object CustomDataTableDef {
val data = TableQuery[CustomDataTableDef]
}
class CustomDataTableDef(tag: Tag) extends Table[CustomDataEntity](tag, "custom"){
def id = column[Int]("id", O.PrimaryKey)
def name = column[String]("name")
def data = column[JsValue]("data")
override def * =
(id,name,data) <> (CustomDataEntity.tupled,CustomDataEntity.unapply(_))
}
导入com.custom.persistence.profile.CustomPostgresProfile.api_
导入play.api.libs.json_
case类CustomDataEntity(id:int,name:String,data:JsValue)
对象CustomDataTableDef{
val data=TableQuery[CustomDataTableDef]
}
类CustomDataTableDef(标记:标记)扩展表[CustomDataEntity](标记,“custom”){
def id=列[Int](“id”,O.PrimaryKey)
def名称=列[字符串](“名称”)
def data=列[JsValue](“数据”)
超控def*=
(id、名称、数据)(CustomDataEntity.tuple、CustomDataEntity.unapply()
}
当我试图编译代码时,我得到以下两个错误
could not find implicit value for parameter tt: slick.ast.TypedType[play.api.libs.json.JsValue]
[error] def data = column[JsValue]("data")
Cannot resolve symbol <>
找不到参数tt:slick.ast.TypedType[play.api.libs.json.JsValue]的隐式值
[error]def data=列[JsValue](“数据”)
无法解析符号
请帮助我解决此问题,您的
对象CustomPostgresProfile
扩展了PostgresProfile
,而不是CustomPostgresProfile
。如果你能解决这个问题,它就会起作用