[英]How would I import tables into another class (/object??) so I can run queries on it in the other class/object? [slick 3.0][scala]
I have two tables defined in a 我在一个表中定义了两个表
class Patients(tag: Tag) extends Table[(String, String, Int, String)](tag, "Patientss") {
def PID = column[String]("Patient Id", O.PrimaryKey)
def Gender = column[String]("Gender")
def Age = column[Int]("Age")
def Ethnicity = column[String]("Ethnicity")
def * = (PID, Gender, Age, Ethnicity)
}
val patientsss = TableQuery[Patients]
class DrugEffect(tag: Tag) extends Table[(String, String, Double)](tag, "DrugEffectss") {
def DrugID = column[String]("Drug ID", O.PrimaryKey)
def PatientID = column[String]("Patient_ID")
def DrugEffectssss = column[Double]("Drug Effect")
def * = (DrugID, PatientID, DrugEffectssss)
def Patient = foreignKey("Patient_FK", PatientID, patientsss)(_.PID)
}
val d_effects = TableQuery[DrugEffect]
I fill in the tables in this particular object/class as well. 我也填写该特定对象/类中的表。
I was wondering how I could call the filled in tables in another object so I can access both DrugEffect
and Patients
as a class, and then run queries on the table itself? 我不知道我怎么会叫填写表中的另一个对象,这样我可以同时访问
DrugEffect
和Patients
为一类,然后再运行查询的表本身?
I hope I'm making myself clear, I don't really have a clue about what I'm doing 我希望我能把自己弄清楚,我对自己在做什么一无所知
What I mean by running queries is something like this: 我通过运行查询的意思是这样的:
val q1 = for {
c <- patientsss if (c.Age === 20 && c.Gender === "F")
s <- d_effects if (s.DrugEffectssss > 10.0)
} yield (c.PID, s.DrugID)
but in an object defined in a different file 但是在另一个文件中定义的对象中
You need the DB API and the table in the separate class. 您需要在单独的类中使用DB API和表。 You can do something like:
您可以执行以下操作:
import tables.Tables
class SeparateClass extends HasDatabaseConfig[JdbcProfile] {
val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
import driver.api._
def get(id: Long) = {
db.run(Tables.DrugEffect.d_effects.filter(_.id === id).result)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.