Skip to content

Commit

Permalink
Action sbt scalafmtAll
Browse files Browse the repository at this point in the history
  • Loading branch information
takapi327 committed Dec 30, 2024
1 parent 9ebda5e commit 019cdd3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
10 changes: 5 additions & 5 deletions module/ldbc-dsl/src/main/scala/ldbc/dsl/codec/Decoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ trait Decoder[A]:

/** Map decoded results to a new type `B`, yielding a `Decoder[B]`. */
def map[B](f: A => B): Decoder[B] = new Decoder[B]:
override def offset: Int = self.offset
override def decode(resultSet: ResultSet, index: Int): B = f(self.decode(resultSet, index))
override def offset: Int = self.offset
override def decode(resultSet: ResultSet, index: Int): B = f(self.decode(resultSet, index))

/** `Decoder` is semigroupal: a pair of decoders make a decoder for a pair. */
def product[B](fb: Decoder[B]): Decoder[(A, B)] = new Decoder[(A, B)]:
Expand All @@ -68,8 +68,8 @@ object Decoder extends TwiddleSyntax[Decoder]:
override def ap[A, B](fab: Decoder[A => B])(fa: Decoder[A]): Decoder[B] =
map(fab.product(fa)) { case (fabb, a) => fabb(a) }
override def pure[A](x: A): Decoder[A] = new Decoder[A]:
override def offset: Int = 0
override def decode(resultSet: ResultSet, index: Int): A = x
override def offset: Int = 0
override def decode(resultSet: ResultSet, index: Int): A = x

given Decoder[String] = (resultSet: ResultSet, index: Int) => resultSet.getString(index)
given Decoder[Boolean] = (resultSet: ResultSet, index: Int) => resultSet.getBoolean(index)
Expand Down Expand Up @@ -101,6 +101,6 @@ object Decoder extends TwiddleSyntax[Decoder]:

given [H, T <: Tuple](using dh: Decoder[H], dt: Decoder[T]): Decoder[H *: T] =
dh.product(dt).map { case (h, t) => h *: t }

given [P <: Product](using mirror: Mirror.ProductOf[P], decoder: Decoder[mirror.MirroredElemTypes]): Decoder[P] =
decoder.to[P]
4 changes: 2 additions & 2 deletions module/ldbc-dsl/src/main/scala/ldbc/dsl/codec/Encoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ object Encoder extends TwiddleSyntax[Encoder]:
def apply[A](using encoder: Encoder[A]): Encoder[A] = encoder

given ContravariantSemigroupal[Encoder] with
override def contramap[A, B](fa: Encoder[A])(f: B => A): Encoder[B] = fa.contramap(f)
override def product[A, B](fa: Encoder[A], fb: Encoder[B]): Encoder[(A, B)] = fa.product(fb)
override def contramap[A, B](fa: Encoder[A])(f: B => A): Encoder[B] = fa.contramap(f)
override def product[A, B](fa: Encoder[A], fb: Encoder[B]): Encoder[(A, B)] = fa.product(fb)

given Encoder[Boolean] with
override def encode(value: Boolean): Encoded =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ package object syntax:
def query: DslQuery[F, B] = DslQuery.Impl[F, B](query.statement, query.params, query.columns.decoder)

def queryTo[P <: Product](using
m1: Mirror.ProductOf[P],
m2: Mirror.ProductOf[B],
check: m1.MirroredElemTypes =:= m2.MirroredElemTypes,
decoder: Decoder[P]
m1: Mirror.ProductOf[P],
m2: Mirror.ProductOf[B],
check: m1.MirroredElemTypes =:= m2.MirroredElemTypes,
decoder: Decoder[P]
): DslQuery[F, P] =
DslQuery.Impl[F, P](query.statement, query.params, decoder)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private[ldbc] case class ColumnImpl[T](
) extends Column[T]:

override def as(name: String): Column[T] =
this.copy(alias = Some(name))
this.copy(alias = Some(name))

override def statement: String =
dataType.fold(s"`$name`")(dataType => s"`$name` ${ dataType.queryString }") + attributes
Expand Down
4 changes: 2 additions & 2 deletions module/ldbc-schema/src/main/scala/ldbc/schema/Table.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ trait Table[T](val $name: String) extends AbstractTable[T]:
ColumnImpl[A](name, Some(s"${ $name }.$name"), decoder, encoder, None, List.empty)

protected final def column[A](name: String, dataType: DataType[A])(using
decoder: Decoder[A],
decoder: Decoder[A],
encoder: Encoder[A]
): Column[A] =
ColumnImpl[A](name, Some(s"${ $name }.$name"), decoder, encoder, Some(dataType), List.empty)

protected final def column[A](name: String, dataType: DataType[A], attributes: Attribute[A]*)(using
decoder: Decoder[A],
decoder: Decoder[A],
encoder: Encoder[A]
): Column[A] =
ColumnImpl[A](name, Some(s"${ $name }.$name"), decoder, encoder, Some(dataType), attributes.toList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ package object syntax:
def query: DslQuery[F, B] = DslQuery.Impl[F, B](query.statement, query.params, query.columns.decoder)

def queryTo[P <: Product](using
m1: Mirror.ProductOf[P],
m2: Mirror.ProductOf[B],
check: m1.MirroredElemTypes =:= m2.MirroredElemTypes,
decoder: Decoder[P]
m1: Mirror.ProductOf[P],
m2: Mirror.ProductOf[B],
check: m1.MirroredElemTypes =:= m2.MirroredElemTypes,
decoder: Decoder[P]
): DslQuery[F, P] =
DslQuery.Impl[F, P](query.statement, query.params, decoder)

Expand Down
38 changes: 19 additions & 19 deletions module/ldbc-statement/src/main/scala/ldbc/statement/Column.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ trait Column[A]:

def imap[B](f: A => B)(g: B => A): Column[B] =
new Column[B]:
override def name: String = self.name
override def alias: Option[String] = self.alias
override def as(name: String): Column[B] = this
override def decoder: Decoder[B] = self.decoder.map(f)
override def encoder: Encoder[B] = (value: B) => self.encoder.encode(g(value))
override def name: String = self.name
override def alias: Option[String] = self.alias
override def as(name: String): Column[B] = this
override def decoder: Decoder[B] = self.decoder.map(f)
override def encoder: Encoder[B] = (value: B) => self.encoder.encode(g(value))
override def updateStatement: String = self.updateStatement
override def duplicateKeyUpdateStatement: String = self.duplicateKeyUpdateStatement
override def values: Int = self.values
Expand Down Expand Up @@ -685,8 +685,8 @@ object Column extends TwiddleSyntax[Column]:
override def alias: Option[String] = None
override def as(name: String): Column[A] = this
override def decoder: Decoder[A] = new Decoder[A]:
override def offset: Int = 0
override def decode(resultSet: ResultSet, index: Int): A = value
override def offset: Int = 0
override def decode(resultSet: ResultSet, index: Int): A = value
override def encoder: Encoder[A] = (value: A) => Encoder.Encoded.success(List.empty)
override def insertStatement: String = ""
override def updateStatement: String = ""
Expand Down Expand Up @@ -746,23 +746,23 @@ object Column extends TwiddleSyntax[Column]:
override def alias: Option[String] = Some(
s"${ left.alias.getOrElse(left.name) } $flag ${ right.alias.getOrElse(right.name) }"
)
override def as(name: String): Column[A] = this
override def decoder: Decoder[A] = _decoder
override def as(name: String): Column[A] = this
override def decoder: Decoder[A] = _decoder
override def encoder: Encoder[A] = _encoder
override def insertStatement: String = ""
override def updateStatement: String = ""
override def duplicateKeyUpdateStatement: String = ""

private[ldbc] case class Count(_name: String, _alias: Option[String])(using
_decoder: Decoder[Int],
_decoder: Decoder[Int],
_encoder: Encoder[Int]
) extends Column[Int]:
override def name: String = s"COUNT($_name)"
override def alias: Option[String] = _alias.map(a => s"COUNT($a)")
override def as(name: String): Column[Int] = this.copy(s"$name.${ _name }")
override def decoder: Decoder[Int] = _decoder
override def encoder: Encoder[Int] = _encoder
override def toString: String = name
override def insertStatement: String = ""
override def updateStatement: String = ""
override def duplicateKeyUpdateStatement: String = ""
override def name: String = s"COUNT($_name)"
override def alias: Option[String] = _alias.map(a => s"COUNT($a)")
override def as(name: String): Column[Int] = this.copy(s"$name.${ _name }")
override def decoder: Decoder[Int] = _decoder
override def encoder: Encoder[Int] = _encoder
override def toString: String = name
override def insertStatement: String = ""
override def updateStatement: String = ""
override def duplicateKeyUpdateStatement: String = ""
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ trait QuerySyntax[F[_]]:
* A [[ldbc.dsl.Query]] instance
*/
def queryTo[P <: Product](using
m1: Mirror.ProductOf[P],
m2: Mirror.ProductOf[B],
check: m1.MirroredElemTypes =:= m2.MirroredElemTypes,
decoder: Decoder[P]
m1: Mirror.ProductOf[P],
m2: Mirror.ProductOf[B],
check: m1.MirroredElemTypes =:= m2.MirroredElemTypes,
decoder: Decoder[P]
): DslQuery[F, P]

0 comments on commit 019cdd3

Please sign in to comment.