Skip to content

Commit

Permalink
Add getAll method support
Browse files Browse the repository at this point in the history
  • Loading branch information
alekslitvinenk committed Nov 18, 2023
1 parent ff4ca12 commit 1a89737
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/scala/io/dockovpn/metastore/db/Queries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ object Queries {
|""".stripMargin.as[(String, String)]
}

def getAllRecords[V](table: String)(implicit rconv: GetResult[V]): SqlStreamingAction[Vector[V], V, Effect] = {
sql"""SELECT * FROM #$table
|""".stripMargin.as[V]
}

// TODO: Implement Predicate -> SQL materializer
private def predicateToSql(predicate: Predicate): String = {
predicate match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ trait AbstractStore[V] {
def put(k: String, v: V): Future[Unit]

def update(k: String, v: V): Future[Unit]

def getAll(): Future[Seq[V]]
}
5 changes: 5 additions & 0 deletions src/main/scala/io/dockovpn/metastore/store/DBStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class DBStore[V <: Product: ClassTag](implicit ec: ExecutionContext, metadataPro
}
}

override def getAll(): Future[Seq[V]] =
dbRef.run(
Queries.getAllRecords(tableMetadata.tableName)
).map(_.asInstanceOf[Vector[V]])

private def getColumnNameToSqlValueMap(v: V, schema: Map[String, String]): Map[String, Any] =
Types.getFieldToValueMap(v)
.map { p =>
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/io/dockovpn/metastore/store/MapStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class MapStore[V <: Product] extends AbstractStore[V] {
override def put(k: String, v: V): Future[Unit] = Future.successful(underlying.addOne(k, v))

override def update(k: String, v: V): Future[Unit] = Future.successful(underlying.update(k, v))


override def getAll(): Future[Seq[V]] = Future.successful(underlying.values.toSeq)
}

object MapStore {
Expand Down

0 comments on commit 1a89737

Please sign in to comment.