Scala + Slick如何将json映射到数据类型为blob的表列

编程入门 行业动态 更新时间:2024-10-28 09:28:16
本文介绍了Scala + Slick如何将json映射到数据类型为blob的表列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要使用slick将json值映射到表,并将整个json作为blob存储在同一表中.

I need to map json values to the table using slick and store whole json as a blob in the same table as well.

def createJob(jobs: JobEntity): Future[Option[Long]] = db.run(job returning job.map((_.id)) += jobs)

我的Json包含类似

id(long),name(string), type(string)

我尝试映射的表有列

id(long),name(string), type(string),json_data(blob)

我的JobEntity类为

I have JobEntity class as

case class JobEntity(id: Option[Long] = None, name: String, type: String) { require(!jobname.isEmpty, "jobname.empty") }

如何将json映射到json_data列?

How do I map the json to the json_data column?

推荐答案

Slick支持以下LOB类型:java.sql.Blob, java.sql.Clob, Array[Byte](请参见文档)

Slick supports the following LOB types: java.sql.Blob, java.sql.Clob, Array[Byte] (see the documentation)

因此,您想使用这些类型之一.您的表定义可能如下所示:

Therefore you want to use one of these types. Your table definition could look like this:

case class Job(id: Option[Long] = None, name: String, `type`: String, json_data: java.sql.Blob) class Jobs(tag: Tag) extends Table[Job](tag, "jobs") { def id = column[Option[Long]]("id") def name = column[String]("name") def `type` = column[String]("type") def json_data = column[java.sql.Blob]("json_data") def * = (id, name, `type`, json_data) <> (Job.tupled, Job.unapply) }

更多推荐

Scala + Slick如何将json映射到数据类型为blob的表列

本文发布于:2023-10-28 01:59:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535167.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   数据类型   Slick   Scala   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!