scala - Insert if not exists in Slick 3.0.0 for bulk insert -


i read answer. how can same bunch insert?

i have list of items, , insert these items:

tbl ++= items 

each item item(id:string, text:string), id primary key.

i want insert not existed items in table tbl using 1 sql query.

slick 3, postgresql

you can try as:

  1. check entries exists in database
  2. filter them out
  3. bulk insert

code sample:

def markasnew(list: seq[issueevent]): future[option[int]] = { val ids = list.map(_.origineventid)).map(_.origineventid) dbrun((for { existing <- events.filter(_.origineventid inset ids).result filtered = list.filter(event => existing.contains(event.origineventid)) count <- events ++= filtered } yield count).transactionally) }


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -