gpt4 book ai didi

java - 我如何将表导入另一个类(/对象??)以便我可以在另一个类/对象中对其运行查询? [圆滑 3.0][scala]

转载 作者:行者123 更新时间:2023-11-28 23:57:46 25 4
gpt4 key购买 nike

我在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]

我也在这个特定的对象/类中填写表格。

我想知道如何在另一个对象中调用填充的表,以便我可以将 DrugEffectPatients 作为一个类访问,然后在表上运行查询本身?

我希望我说清楚了,我真的不知道我在做什么

运行查询的意思是这样的:

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)

但在不同文件中定义的对象中

最佳答案

您需要单独类中的 DB API 和表。你可以这样做:

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)
}
}

关于java - 我如何将表导入另一个类(/对象??)以便我可以在另一个类/对象中对其运行查询? [圆滑 3.0][scala],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31078567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com