Skip to content
/ hf Public

A scala slick plugin. Dynamically update columns in runtime without reflect and macro.

License

Notifications You must be signed in to change notification settings

scalax/hf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slick-summer -- slick update功能增强

English

简介

Persons.filter(_.id === id).map { p =>
  (p.name, p.address, p.postcode, p.updateTime)
}.update(("foo", "bar", "baz", now))

以上是一个典型的slick update例子,api设计的很合理和collection基本一致 但很难实现以下需求

  • 选择性更新某几列
  • 更新超过22列

本项目实现了以上功能,然而一定程度上破坏了和collection的一致性

import net.scalax.hf._
import slick.driver.H2Driver.api._

val updateQ =
  for {
    small <- smallTq.filter(_.id === 2333L).hf
  } yield {
    List(
      small.a1 setTo 2333,
      small.a2 setTo Some(2333),
      small.a3 setTo "wang"
    )
  }
updateQ.update //update DBIO
updateQ.insert //insert DBIO

另外新增了when来做选择性更新

import net.scalax.hf._
import slick.driver.H2Driver.api._

val updateQ =
  for {
    small <- smallTq.hf if small.id === 2333L
  } yield {
    List(
      small.a1 setTo 2333 when ("github" == "github"),
      small.a2 setTo Some(2333) when ("scala" == "china"),
      small.a3 setTo "wang"
    )
  }
updateQ.update //update DBIO
updateQ.insert //insert DBIO

如何使用可以查看单元测试

实现思路

将更新列转化为C1 -> C2 -> C3 -> ... -> Cn的形式,然后自动提供Shape

About

A scala slick plugin. Dynamically update columns in runtime without reflect and macro.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages