<> 有什么作用?运营商在Slick做什么? [英] What does the <> operator do in Slick?

查看:37
本文介绍了<> 有什么作用?运营商在Slick做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览 Slick 文档 以设置一个快速工作原型.

I was walking through the documentation of Slick to setup a quick working prototype.

在映射表部分,我在提到的示例中看到了 <> 运算符,但在任何地方都找不到任何相关文档.需要帮助来理解这一点.

In the Mapped Tables section I see a <> operator in the example mentioned but can't find any documentation for that anywhere. Need help in understanding this.

推荐答案

<> 运算符定义了 Table<中 Row 之间的关系/code> 和一个 case 类.

The <> operator defines a relation between a Row in the Table and a case class.

case class User(id: Option[Int], first: String, last: String)

ROW            |id             | first        | last        |

所以首先将数据从 Tabels 中取出作为 n-tuple(<> 的左侧),然后转换为 caseclass(<> 的右侧).

So the data first is taken out of the Tabels as an n-tuple (left side of <>) and then transformed to the case class (right side of <>).

要使案例类的转换起作用,需要两种方法:

To make the transformation of the case class work one needs two kinds of methods:

scala> User.tupled
res6: ((Option[Int], String, String)) => User = <function1>

所以当给定一个三元组 (Option[Int], String, String) 作为参数时,这个函数可以创建一个 User.

So this function can create a User when given a triple (Option[Int], String, String) as an argument.

scala> User.unapply _
res7: User => Option[(Option[Int], String, String)] = <function1>

该函数提供了相反的功能.给定一个用户,它可以提取一个三元组.这种模式称为 Extractor.您可以在这里了解更多信息:http://www.scala-lang.org/old/node/112

This function provides the functionality with the other way round. Given a user it can extract a triple. This pattern is called an Extractor. Here you can learn more about this: http://www.scala-lang.org/old/node/112

这篇关于&lt;&gt; 有什么作用?运营商在Slick做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆