From 24d4f0d31e9d8be08696009337aa4cb9783cb0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=C4=8Dera?= Date: Mon, 11 Sep 2023 17:22:37 +0200 Subject: [PATCH 1/5] use && from Scala compiletime ops --- src/main/Expression.scala | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/Expression.scala b/src/main/Expression.scala index 3ad4ea8..daf0870 100644 --- a/src/main/Expression.scala +++ b/src/main/Expression.scala @@ -4,18 +4,15 @@ import scala.annotation.targetName import utils.IsTupleOf import Tuple.Fold +import scala.compiletime.ops.boolean.* type Numeric = Int | Long | Float | Double type Primitive = Numeric | String | Char | Boolean -type LogicalAnd[A, B] <: Boolean = (A, B) match - case (true, true) => true - case _ => false - type ForAll[T <: Tuple, Pred[X] <: Boolean] <: Boolean = T match case EmptyTuple => true - case h *: t => LogicalAnd[Pred[h], ForAll[t, Pred]] + case h *: t => Pred[h] && ForAll[t, Pred] type CanSelectExpr[T] <: Boolean = T match case Expression[?, true] => true From 552742121006d1ab2d37f55c887264511e9e73e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=C4=8Dera?= Date: Mon, 11 Sep 2023 17:22:59 +0200 Subject: [PATCH 2/5] string length --- src/main/Expression.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/Expression.scala b/src/main/Expression.scala index daf0870..04346e6 100644 --- a/src/main/Expression.scala +++ b/src/main/Expression.scala @@ -173,10 +173,11 @@ extension (lhs: Expression[?, ?]) infix def +[T, S <: Boolean](rhs: Expression[T, S]) = lhs.concat(rhs) -extension (lhs: Expression[String, ?]) +extension [S <: Boolean] (lhs: Expression[String, S]) def startsWith(rhs: String) = StartsWith(needle = rhs, haystack = lhs) def endsWith(rhs: String) = EndsWith(needle = rhs, haystack = lhs) def contains(rhs: String) = Contains(needle = rhs, haystack = lhs) + def length = Function[Int]("LENGTH", lhs) extension [T <: Numeric | Null, E <: Expression[T, true]] (qb: QueryBuilder[E]) From 599145556e70acb81861488777be1287b731833d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=C4=8Dera?= Date: Mon, 11 Sep 2023 17:23:31 +0200 Subject: [PATCH 3/5] remove unused import --- src/main/ScopeFactory.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/ScopeFactory.scala b/src/main/ScopeFactory.scala index b43737e..663aa5d 100644 --- a/src/main/ScopeFactory.scala +++ b/src/main/ScopeFactory.scala @@ -2,7 +2,6 @@ package tyqu import scala.quoted.* import scala.annotation.tailrec -import org.checkerframework.checker.units.qual.m trait RefinedScope[S <: Scope]: From 03b3a6e53b4a48afdff03e0ef719da344df5e270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=C4=8Dera?= Date: Mon, 11 Sep 2023 17:23:42 +0200 Subject: [PATCH 4/5] remove demo --- src/demo/Demo.scala | 67 --------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/demo/Demo.scala diff --git a/src/demo/Demo.scala b/src/demo/Demo.scala deleted file mode 100644 index 23b9f62..0000000 --- a/src/demo/Demo.scala +++ /dev/null @@ -1,67 +0,0 @@ -//> using lib "org.postgresql:postgresql:42.5.1" - -package tyqu_demo - -import java.sql.DriverManager - -import tyqu.{*, given} -import tyqu.execution.QueryExecutor -import tyqu.translators.GenericSqlTranslator -import tyqu.platforms.* -import tyqu.execution.PostgreSqlQueryExecutor -import tyqu.execution.RefinedResult - - -case object Releases extends Table: - val id = Column[Int](primary = true) - val title = Column[String]() - val country = Column[String]() - val genre = Column[String]() - - lazy val artists = ManyToMany(Artists, ReleasedBy, ReleasedBy.releaseId, ReleasedBy.artistId) - lazy val tracks = OneToMany(Tracks, Tracks.release) - - -case object Tracks extends Table: - val id = Column[Int](primary = true) - val releaseId = Column[Int]() - val position = Column[String]() - val title = Column[String]() - val duration = Column[Int]() - - lazy val release = ManyToOne(Releases, releaseId) - - -case object Artists extends Table: - val id = Column[Int](primary = true) - val name = Column[String]() - val realName = Column[String]() - val profile = Column[String]() - val url = Column[String] - - lazy val releases = ManyToMany(Releases, ReleasedBy, ReleasedBy.artistId, ReleasedBy.releaseId) - - -case object ReleasedBy extends Table: - val releaseId = Column[Int]() - val artistId = Column[Int]() - - -object Demo: - def main(args: Array[String]) = - val connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/discogs?user=postgres&password=BigData1&ssl=false").nn - given PostgreSqlQueryExecutor(connection) - - val q = - // Find out the average track duration. - - // List the titles of all releases by Radiohead that contain less than 5 tracks, sorted in alphabetical order. - - // What are the names and IDs of the top 10 artists with the most releases? - - // How many artists have at least 10000 seconds of released music (i.e., total track duration >= 10000) and at least one release with the genre 'Classical'? - from(Releases).limit(10).map(_.id * 2) - - // println(translator.translate(q)) - - q.execute().foreach(println) From eb5c8745d54ebc3f3dd18e53a9dcb3adecadc43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=C4=8Dera?= Date: Mon, 11 Sep 2023 17:24:40 +0200 Subject: [PATCH 5/5] update version in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9fcf29f..34450ca 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,12 @@ Installation ------------ With Scala CLI: add the following to your `project.scala` file. ```scala -//> using dep "ch.epfl.tyqu::tyqu:0.0.1" +//> using dep "ch.epfl.tyqu::tyqu:0.1.0" ``` With sbt: add the following to your `build.sbt` file. ```scala -libraryDependencies += "ch.epfl.tyqu" %% "tyqu" % "0.0.1" +libraryDependencies += "ch.epfl.tyqu" %% "tyqu" % "0.1.0" ``` Usage