Skip to content

Commit

Permalink
Added batch get
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Jan 20, 2024
1 parent 8c81ef5 commit a7a0e5f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions driver/src/main/scala/com/outr/arango/core/ArangoDBDocuments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ trait ArangoDBDocuments[T] {
.map(deleteDocumentEntityConversion(_, toT))

object batch {
def get(ids: List[Id[T]]): IO[List[Option[T]]] = io(_collection.getDocuments(ids.map(_._key).asJava, classOf[Json]))
.map(entity => entity.getDocuments.asScala.toList.map(json => Option(json).map(toT)))

def apply(ids: List[Id[T]], failOnMissing: Boolean = false): IO[List[T]] = get(ids).map(_.flatten).map { list =>
if (failOnMissing && ids.length != list.length) {
throw new RuntimeException(s"Missing results! Expected ${ids.length} but received ${list.length}.")
}
list
}

def insert(docs: List[T], options: CreateOptions = CreateOptions.Insert, transaction: StreamTransaction = None.orNull): IO[CreateResults[T]] = {
val insert = io(_collection.insertDocuments(
docs.map(fromT).asJava,
Expand Down

0 comments on commit a7a0e5f

Please sign in to comment.