Skip to content

Commit

Permalink
Added getAll convenience method
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Aug 10, 2024
1 parent e83a99d commit 06f0718
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions async/src/main/scala/lightdb/async/AsyncCollection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ case class AsyncCollection[Doc <: Document[Doc], Model <: DocumentModel[Doc]](un
def get(id: Id[Doc])(implicit transaction: Transaction[Doc]): IO[Option[Doc]] =
IO.blocking(underlying.get(id))

def getAll(ids: Seq[Id[Doc]])(implicit transaction: Transaction[Doc]): fs2.Stream[IO, Doc] =
fs2.Stream.fromBlockingIterator[IO](underlying.getAll(ids), 512)

def apply(id: Id[Doc])(implicit transaction: Transaction[Doc]): IO[Doc] =
IO.blocking(underlying(id))

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/scala/lightdb/collection/Collection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ case class Collection[Doc <: Document[Doc], Model <: DocumentModel[Doc]](name: S
store.get(model._id, id)
}

def getAll(ids: Seq[Id[Doc]])(implicit transaction: Transaction[Doc]): Iterator[Doc] = ids
.iterator
.flatMap(get)

def apply(id: Id[Doc])(implicit transaction: Transaction[Doc]): Doc =
store.get(model._id, id).getOrElse {
throw DocNotFoundException(name, "_id", id)
Expand Down

0 comments on commit 06f0718

Please sign in to comment.