Skip to content

Commit 40c3237

Browse files
committed
fix formatting
1 parent 0de7f5c commit 40c3237

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

docs/tutorial.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,10 @@ db.run(query) ==>
504504
505505
You can also use named tuples to map the results of a query.
506506
```scala
507+
// `NamedTupleQueryable` is also included by `import scalasql.simple.given`
507508
import scalasql.namedtuples.NamedTupleQueryable.given
508509

509-
val query = Country.select.map(c =>
510-
(name = c.name, continent = c.continent)
511-
)
510+
val query = Country.select.map(c => (name = c.name, continent = c.continent))
512511

513512
db.run(query).take(5) ==> Seq(
514513
(name = "Afghanistan", continent = "Asia"),
@@ -541,12 +540,12 @@ val query = Country.select.map(c =>
541540

542541
db.run(query).take(5).match {
543542
case Seq(
544-
Country(name = "🌐 Afghanistan", population = 0L),
545-
Country(name = "🌐 Netherlands", population = 0L),
546-
Country(name = "🌐 Netherlands Antilles", population = 0L),
547-
Country(name = "🌐 Albania", population = 0L),
548-
Country(name = "🌐 Algeria", population = 0L)
549-
) =>
543+
Country(name = "🌐 Afghanistan", population = 0L),
544+
Country(name = "🌐 Netherlands", population = 0L),
545+
Country(name = "🌐 Netherlands Antilles", population = 0L),
546+
Country(name = "🌐 Albania", population = 0L),
547+
Country(name = "🌐 Algeria", population = 0L)
548+
) =>
550549
} ==> ()
551550
```
552551

scalasql/namedtuples/src/NamedTupleQueryable.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ object NamedTupleQueryable {
99
opaque type Rows[X <: Tuple, +Y <: Tuple] = List[Queryable.Row[?, ?]]
1010

1111
object Rows {
12-
// currently "traditional" recursive implicit search
13-
// because we only know the Q type, and it appears compiletime.summonAll cannot be used to refined the R type
14-
// e.g. compiletime.summonAll[Tuple.Map[Qs, [X] =>> Queryable.Row[X, ?]]] does nothing because its static type is fixed.
12+
// it seems "traditional" recursive implicit search is the only way to infer the types of `R` when only `Qs` is known.
13+
// see https://gist.github.com/bishabosha/e630f76384093153b17f1498a9459518 for a variant that
14+
// uses compiletime.summonAll, but it does a double implicit search, so wasnt chosen for the moment.
15+
1516
given concatRows: [Q, R, Qs <: Tuple, Rs <: Tuple]
1617
=> (x: Queryable.Row[Q, R])
1718
=> (xs: Rows[Qs, Rs])

scalasql/namedtuples/src/SimpleTable.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,18 @@ object SimpleTable {
116116

117117
/** A single update to a field of a `Record[C, T]`, used by [[Record#updates]] */
118118
final class Patch private[SimpleTable] (
119-
private[SimpleTable] val idx: Int,
120-
private[SimpleTable] val f: AnyRef => AnyRef
119+
private[SimpleTable] val idx: Int,
120+
private[SimpleTable] val f: AnyRef => AnyRef
121121
)
122122

123123
/** A `Field[T]` is used to create a patch for a field in a [[SimpleTable.Record Record]]. */
124124
final class Field[T](private val factory: (T => T) => Patch) extends AnyVal
125125
object Field {
126126
extension [T](field: Field[T]) {
127+
127128
/** Create a patch that replaces the old value with `x` */
128129
def :=(x: T): Patch = field.factory(Function.const(x))
130+
129131
/** Create a patch that can transform the old value with `f` */
130132
def apply(f: T => T): Patch = field.factory(f)
131133
}

scalasql/namedtuples/test/src/example/WorldSqlTestsNamedTuple.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,10 @@ object WorldSqlTestsNamedTuple extends TestSuite {
444444
// Below, we query the `country` table, but only want the `name` and `continent` of
445445
// each country, without all the other metadata:
446446
// +SNIPPET [MAP-1]
447+
// `NamedTupleQueryable` is also included by `import scalasql.simple.given`
447448
import scalasql.namedtuples.NamedTupleQueryable.given
448449

449-
val query = Country.select.map(c =>
450-
(name = c.name, continent = c.continent)
451-
)
450+
val query = Country.select.map(c => (name = c.name, continent = c.continent))
452451
// -SNIPPET [MAP-1]
453452
db.renderSql(query) ==> """
454453
SELECT country0.name AS res_0, country0.continent AS res_1
@@ -497,12 +496,12 @@ object WorldSqlTestsNamedTuple extends TestSuite {
497496
// +SNIPPET [MAP-4]
498497
db.run(query).take(5).match {
499498
case Seq(
500-
Country(name = "🌐 Afghanistan", population = 0L),
501-
Country(name = "🌐 Netherlands", population = 0L),
502-
Country(name = "🌐 Netherlands Antilles", population = 0L),
503-
Country(name = "🌐 Albania", population = 0L),
504-
Country(name = "🌐 Algeria", population = 0L)
505-
) =>
499+
Country(name = "🌐 Afghanistan", population = 0L),
500+
Country(name = "🌐 Netherlands", population = 0L),
501+
Country(name = "🌐 Netherlands Antilles", population = 0L),
502+
Country(name = "🌐 Albania", population = 0L),
503+
Country(name = "🌐 Algeria", population = 0L)
504+
) =>
506505
} ==> ()
507506
// -SNIPPET [MAP-4]
508507
}

0 commit comments

Comments
 (0)