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:
- check entries exists in database
- filter them out
- 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
Post a Comment