Scala slick MySQL field too many tuple issues

Source: Internet
Author: User

The original synchronization service is normal, due to the need, the other Side single table new fields, more than 22

SBT Assembly Compilation Error

Too many elements for tuple:26, allowed:22

Scala case class supports a maximum of 22 construction parameters

And find a way out.

Https://underscore.io/blog/posts/2016/10/11/twenty-two.html

https://github.com/slick/slick/issues/519#issuecomment-48327043

Https://github.com/underscoreio/slickless/issues/16

Final Application Slickless Solution

Some examples

ImportSlick.jdbc.H2Profile.api._ImportShapeless. {Hlist,::,Hnil,Generic}ImportSlickless._CaseClassUser (Id:Long,EmailString)ClassUsers (TagTAG)Extendstable[User] (tag,The Users") {DefId= column[Long] ( "id", O.PrimaryKey, o.AutoInc) def email = column[  String] ("email") def * = (ID :: Email :: hnil). Mappedwith (generic[  User])}lazy val users = tablequery[users]        

 

Conversion based on tupled required

    Case (byoffset_get,lastid:int) + = {println ("Sync Start by", LastID) val words = Tablequery[words]// Val Action=origin_db.run (Word.filter (_.id > LastID). Take (page_size). Result) Val Action=origin_db.run (words.f Ilter (_.id > LastID). Take (page_size). Result) Action.oncomplete (data=>{println ("Sync get Data", Data.get.          Length) if (data.issuccess) {val Words=data.get.tolist.map (a=>{word.tupled (A)}) if (words.length>0) {future {println (S "Blocking next page 1s start") time Unit.SECONDS.sleep (1) println (S "Blocking next page 1s finished")//sync only consider insert if ( Is_just_insert) {Self! ( Byoffset_insert,words)}else{//If historical data is updated self! (              byoffset_insert_update,words)}}}else{//Get the latest data wait 5 minutes future { PrinTLN (S "Blocking future 5m Start") TimeUnit.MINUTES.sleep (5) println (S "Blocking the future 5m finished ") Self!          (Byoffset_get,lastid)} }}else{
 Future {
println (S "Blocking table" +tablename+ "future 5m start")
TimeUnit.MINUTES.sleep (5)
println (S "Blocking table" +tablename+ "future 5m finished")
Self! ( Byoffset_get,lastid)
}
}
      })    }    //Insert Data Case    (Byoffset_insert,words:list[word]) =>{      println ("Insert Start", words.length)      val word = tablequery[words]      word.++= (words.map (a=>{        word.unapply (a). Get      }))      //word.+= ( Word.unapply (Words.head). Get)      val insertactions = dbio.seq (          word.++= (Words.map (a=>{ Word.unapply (a). Get        }))      Dest_db.run (insertactions). OnComplete (data=>{       if ( data.issuccess) {        println ("Insert data result", data)        //Add succeeded after updating last table         val lastid=words.last.id         Sync.lastactor! (Byoffset_upsert_offset,tablename,lastid)       } else{Self          ! ( byoffset_insert,words)}}      )    }

 

Based on Hlists/generics, you do not

  Case (byoffset_get,lastid:int) + = {println ("table" +tablename+ "Sync Start by", LastID) val users = Tableq Uery[users]//Val Action=origin_db.run (User.filter (_.id > LastID). Take (page_size). Result) Val Action=or  Igin_db.run (Users.filter (_.id > LastID). Take (page_size). Result) Action.oncomplete (data=>{println ("table  "+tablename+" Sync get Data ", Data.get.length) if (data.issuccess) {val Users=data.get.tolist if (users.length>0) {future {println (S "Blocking table" +tablename+ "next page 1s start") timeunit.seco              Nds.sleep (1) println (S "Blocking table" +tablename+ "next page 1s finished")//sync only consider insert if (Is_just_insert) {self! ( Byoffset_insert,users)}else{//If historical data is updated self! (            byoffset_insert_update,users)}}}else{Future {  println (S "Blocking table" +tablename+ "future 5m Start") TimeUnit.MINUTES.sleep (5) println (S " Blocking table "+tablename+" 5m finished ") Self!          (Byoffset_get,lastid)} }}else{Future {println (S "Blocking table" +tablename+ "The Future 5m start") Ti MeUnit.MINUTES.sleep (5) println (S "Blocking table" +tablename+ "future 5m finished") Self!        (Byoffset_get,lastid)} }})}//Insert data case (Byoffset_insert,users:list[user]) =>{println ("table" +tablename+ "Insert Star T ", users.length) val user = Tablequery[users]//user.+= (user.unapply (users.head). Get) Val insertactions = D        Bio.seq (user++=users) dest_db.run (insertactions) OnComplete (data=>{if (data.issuccess) {   println ("table" +tablename+ "Insert data result", data)//Added after successful update last table Val lastid=users.last.id      Sync.lastactor! (Byoffset_upsert_offset,tablename,lastid)} else{Self! ( byoffset_insert,users)}})}  

Scala Slick heterogeneous Table synchronization Service

Https://github.com/cclient/ScalaMysqlSync

Scala slick MySQL field too many tuple issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.