如何为可选提升列指定“无”

时间:2016-07-03 09:54:46

标签: sql scala join slick

假设我有一些像这样的关联表:

val ca = for {
  customer <- customers
  account <- accounts // if (... some complex logic here ---)
} yield (customer, account)

现在我想在某些特定情况下加入一个表:

val one = for {
  result <- ca joinRight products on (_._1.name === _.name)
} yield result

我强行要获得以下结构的结果:

Query[(Rep[Option[(Customers, Accounts)]], Products), (Option[(CustomersRow, AccountsRow)], ProductsRow), scala.Seq]

如何过滤掉不存在的(客户,帐户)记录并将输出更改为此?

Query[(Customers, Accounts, Products), (CustomersRow, AccountsRow, ProductsRow), scala.Seq]

2 个答案:

答案 0 :(得分:0)

与您与客户和帐户编写第一次联接的方式相同。

val ca = for {
  customer <- customers
  account <- accounts // if (... some complex logic here ---)
  product <- products if (customer.name === product.name)
} yield (customer, account, product)

答案 1 :(得分:0)

let logger = Logger() let pipe = NSPipe() logger.pipe = pipe logger.enabled = false logger.useCurrentThread = true // The logs generally use a background thread to prevent interrupting the main queue. In this test, the current thread must be used in order for it to be synchronous. let writtenData = "written data".dataUsingEncoding(NSUTF8StringEncoding)! logger.pipe!.fileHandleForWriting.writeData(writtenData) logger.debug("Test message") XCTAssertEqual(logger.pipe!.fileHandleForReading.availableData.length, writtenData.length) 应该给你回复

joinLeft

Query[((Customers, Accounts), Rep[Option[Products]]), ((CustomersRow, AccountsRow), Option[ProductsRow]), scala.Seq] ,然后使用Seq[((CustomersRow, AccountsRow), Option[ProductsRow])]等方式执行任何操作...