Skip to content

Commit

Permalink
Db -> Expr
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Dec 10, 2023
1 parent 9bcc727 commit 58d29fd
Show file tree
Hide file tree
Showing 96 changed files with 1,145 additions and 1,162 deletions.
8 changes: 4 additions & 4 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ trait ScalaSql extends Common{
os.write(
T.dest / "Generated.scala",
s"""package scalasql.core.generated
|import scalasql.core.{Queryable, Db}
|import scalasql.core.{Queryable, Expr}
|trait QueryableRow{
| ${queryableRowDefs.mkString("\n")}
|}
Expand Down Expand Up @@ -133,7 +133,7 @@ trait ScalaSql extends Common{
|
|""".stripMargin
s"""def batched[${commaSep(j => s"T$j")}](${commaSep(j => s"f$j: V[Column] => Column[T$j]")})(
| items: (${commaSep(j => s"Db[T$j]")})*
| items: (${commaSep(j => s"Expr[T$j]")})*
|)(implicit qr: Queryable[V[Column], R]): scalasql.query.InsertColumns[V, R] $impl""".stripMargin
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ trait ScalaSql extends Common{
os.write(
T.dest / "Generated.scala",
s"""package scalasql.generated
|import scalasql.core.{Queryable, Db}
|import scalasql.core.{Queryable, Expr}
|import scalasql.query.Column
|trait Insert[V[_[_]], R]{
| ${defs(false).mkString("\n")}
Expand All @@ -182,7 +182,7 @@ trait ScalaSql extends Common{
| def newInsertValues[R](
| insert: scalasql.query.Insert[V, R],
| columns: Seq[Column[_]],
| valuesLists: Seq[Seq[Db[_]]]
| valuesLists: Seq[Seq[Expr[_]]]
| )(implicit qr: Queryable[V[Column], R]): scalasql.query.InsertColumns[V, R]
| ${defs(true).mkString("\n")}
|}
Expand Down
4 changes: 2 additions & 2 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ API rather than a SQL-like API:

**ScalaSql**
```scala
def songs = MusicDb.songs.filter(_.artistId === id)
def songs = MusicExpr.songs.filter(_.artistId === id)

val studentsWithAnAddress = students.filter(s => addresses.filter(a => s.addressId === a.id).nonEmpty)
```
**Squeryl**
```scala
def songs = from(MusicDb.songs)(s => where(s.artistId === id) select(s))
def songs = from(MusicExpr.songs)(s => where(s.artistId === id) select(s))

val studentsWithAnAddress = from(students)(s =>
where(exists(from(addresses)((a) => where(s.addressId === a.id) select(a.id))))
Expand Down
8 changes: 4 additions & 4 deletions docs/generateDocs.sc
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def generateTutorial(sourcePath: os.Path, destPath: os.Path) = {
os.write.over(destPath, outputLines.mkString("\n"))
}
def generateReference(dest: os.Path, scalafmtCallback: (Seq[os.Path], os.Path) => Unit) = {
def dropDbPrefix(s: String) = s.split('.').drop(2).mkString(".")
def dropExprPrefix(s: String) = s.split('.').drop(2).mkString(".")
val records = upickle.default.read[Seq[Record]](os.read.stream(os.pwd / "out" / "recordedTests.json"))
val suiteDescriptions = upickle.default.read[Map[String, String]](os.read.stream(os.pwd / "out" / "recordedSuiteDescriptions.json"))
.map{case (k, v) => (dropDbPrefix(k), v)}
.map{case (k, v) => (dropExprPrefix(k), v)}

val rawScalaStrs = records.flatMap(r => Seq(r.queryCodeString) ++ r.resultCodeString)
val formattedScalaStrs = {
Expand Down Expand Up @@ -129,8 +129,8 @@ def generateReference(dest: os.Path, scalafmtCallback: (Seq[os.Path], os.Path) =
.groupBy(_.suiteName)
.toSeq
.sortBy(_._2.head.suiteLine)
.distinctBy { case (k, v) => dropDbPrefix(k)}
.map{case (k, vs) => (dropDbPrefix(k), vs.map(r => r.copy(suiteName = dropDbPrefix(r.suiteName))))}
.distinctBy { case (k, v) => dropExprPrefix(k)}
.map{case (k, vs) => (dropExprPrefix(k), vs.map(r => r.copy(suiteName = dropExprPrefix(r.suiteName))))}

for((suiteName, suiteGroup) <- recordsWithoutDuplicateSuites) {
val seen = mutable.Set.empty[String]
Expand Down
Loading

0 comments on commit 58d29fd

Please sign in to comment.