Reputation: 53
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?
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
Upvotes: 1
Views: 515
Reputation: 11508
You need the DB API and the table in the separate class. 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)
}
}
Upvotes: 1