내가 틀릴 수도 있지만 대부분의 기존 관계형 데이터베이스는 단일 작업 내에서 여러 데이터베이스로 확장 할 수 없습니다. 그러나 위의 내용은 schema
을 사용하여 쉽게 얻을 수 있습니다. (실제로 작성한 SQL이라고 생각합니다. 붙여 넣은 SQL로 판단하십시오.)
예를 들어 보겠습니다. 나는 그러나 변경하는 경우
select x2."STUDENT_ID", x2."NAME", x2."UUID", x2."ID", x3."NAME", x3."MIDDLE_NAME", x3."SURNAME", x3."NATIONALITY", x3."ID"
from "DOCUMENT" x2
left outer join "STUDENT" x3 on x2."STUDENT_ID" = x3."ID"
where x3."NAME" = 'Test'
: 다음과 같은 SQL을 생성합니다
DocumentTable
.joinLeft(StudentTable).on(_.studentId === _.id)
.filter { case(doc, student) => student.map(_.name) === "Test" }
:
// student
case class Student(name: String,
middleName: Option[String],
surname: String,
nationality: String,
id: Id[Student] = Id.none)
class StudentTable(tag: Tag) extends Table[Student](tag, "STUDENT") {
def name = column[String]("NAME")
def middleName = column[Option[String]]("MIDDLE_NAME")
def surname = column[String]("SURNAME")
def nationality = column[String]("NATIONALITY")
def id = column[Id[Student]]("ID", O.PrimaryKey, O.AutoInc)
def * = (name, middleName, surname, nationality, id) <> (Student.tupled, Student.unapply)
}
lazy val StudentTable = TableQuery[StudentTable]
// document
case class Document(studentId: Option[Id[Student]],
name: String,
uuid: String,
id: Id[Document] = Id.none)
class DocumentTable(tag: Tag) extends Table[Document](tag, "DOCUMENT") {
def studentId = column[Option[Id[Student]]]("STUDENT_ID")
def name = column[String]("NAME")
def uuid = column[String]("UUID")
def id = column[Id[Document]]("ID", O.PrimaryKey, O.AutoInc)
def * = (studentId, name, uuid, id) <> (Document.tupled, Document.unapply)
def student = foreignKey("fk_document_student", studentId, StudentTable)(_.id.?)
}
lazy val DocumentTable = TableQuery[DocumentTable]
는 다음과 같은 쿼리를 수행 :의는 다음과 같이 우리가 우리의 Slick
- 관련 코드 내에서 정의 된 두 개의 테이블이 있다고 가정하자 내 테이블 정의 :
class StudentTable(tag: Tag) extends Table[Student](tag, _schemaName = Option("database2"), "STUDENT") {
...
- - 특정 테이블을 지정 스키마에 의해 접두사해야 함을 나타냅니다 나는 하나 개의 매개 변수를 추가3210
이
class DocumentTable(tag: Tag) extends Table[Document](tag, _schemaName = Option("database1"), "DOCUMENT") {
...
알 수 있습니다. 내가 가진 것
는 (같은 슬릭 쿼리) 다음과 같은 SQL 지금 생성 : 보인다
select x2."STUDENT_ID", x2."NAME", x2."UUID", x2."ID", x3."NAME", x3."MIDDLE_NAME", x3."SURNAME", x3."NATIONALITY", x3."ID"
from "database1"."DOCUMENT" x2
left outer join "database2"."STUDENT" x3 on x2."STUDENT_ID" = x3."ID"
where x3."NAME" = 'Test'
가 당신이 달성하고자하는 것을 정확하게합니다.