diff --git a/src/main/scala/io/dockovpn/metastore/db/Queries.scala b/src/main/scala/io/dockovpn/metastore/db/Queries.scala index ab3d998..13f16a9 100644 --- a/src/main/scala/io/dockovpn/metastore/db/Queries.scala +++ b/src/main/scala/io/dockovpn/metastore/db/Queries.scala @@ -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 { diff --git a/src/main/scala/io/dockovpn/metastore/store/AbstractStore.scala b/src/main/scala/io/dockovpn/metastore/store/AbstractStore.scala index c725b98..8712e18 100644 --- a/src/main/scala/io/dockovpn/metastore/store/AbstractStore.scala +++ b/src/main/scala/io/dockovpn/metastore/store/AbstractStore.scala @@ -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]] } diff --git a/src/main/scala/io/dockovpn/metastore/store/DBStore.scala b/src/main/scala/io/dockovpn/metastore/store/DBStore.scala index 06e4e76..18a08de 100644 --- a/src/main/scala/io/dockovpn/metastore/store/DBStore.scala +++ b/src/main/scala/io/dockovpn/metastore/store/DBStore.scala @@ -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 => diff --git a/src/main/scala/io/dockovpn/metastore/store/MapStore.scala b/src/main/scala/io/dockovpn/metastore/store/MapStore.scala index a7220ae..d4c113f 100644 --- a/src/main/scala/io/dockovpn/metastore/store/MapStore.scala +++ b/src/main/scala/io/dockovpn/metastore/store/MapStore.scala @@ -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 {