Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/2024 01 fix scalafmt settings #108

Merged
merged 7 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.5.2
version = 3.7.17

maxColumn = 120

Expand Down Expand Up @@ -85,3 +85,12 @@ newlines.implicitParamListModifierPrefer = after
newlines.beforeCurlyLambdaParams = multilineWithCaseOnly

rewrite.trailingCommas.style = never
rewrite.scala3.convertToNewSyntax = true

fileOverride {
"glob:**/plugin/**/*.scala" {
runner.dialect = scala212
rewrite.scala3.convertToNewSyntax = false
runner.dialectOverride.allowSignificantIndentation = false
}
}
2 changes: 1 addition & 1 deletion benchmark/src/main/scala/benchmark/jdbc/Select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Select:
statement.setInt(1, len)
val resultSet = use(statement.executeQuery())
val records = List.newBuilder[(Int, String, String)]
while (resultSet.next()) {
while resultSet.next() do {
val code = resultSet.getInt(1)
val name = resultSet.getString(2)
val region = resultSet.getString(3)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/ldbc/core/Alias.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private[ldbc] trait Alias:
label: String,
dataType: DataType[T],
attributes: Attribute[T]*
): Column[T] = Column[T](label, dataType, attributes: _*)
): Column[T] = Column[T](label, dataType, attributes*)

def COMMENT[T](message: String): Comment[T] = Comment[T](message)

Expand Down
21 changes: 11 additions & 10 deletions core/src/main/scala/ldbc/core/DataType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1158,10 +1158,10 @@ object DataType:
* Scala types that match SQL DataType
*/
private[ldbc] case class Enum[T <: EnumModel | Option[EnumModel]](
isOptional: Boolean,
character: Option[Character] = None,
collate: Option[Collate[T]] = None,
default: Option[Default] = None
isOptional: Boolean,
character: Option[Character] = None,
collate: Option[Collate[T]] = None,
default: Option[Default] = None
)(using enumDataType: EnumDataType[?])
extends DataType[T]:

Expand Down Expand Up @@ -1448,12 +1448,13 @@ object DataType:
case _: Option[?] =>
this.copy(default = Some(value.asInstanceOf[Option[?]].fold(Default.Null)(Default.Value(_))))
case v: Int =>
inline if (
(constValue[v.type >= 0] & constValue[v.type <= 0]) | (constValue[
v.type >= 1901
] & constValue[v.type <= 2155])
)
then this.copy(default = Some(Default.Value(value)))
// TODO: Scalafmt removes extra parentheses that wrap the entire condition.
// It detects it as extra parentheses, but if you remove those parentheses, the if ... then writing method results in an error
// Therefore, the variable is used to avoid the error.
inline val bool = (constValue[v.type >= 0] & constValue[v.type <= 0]) | (constValue[
v.type >= 1901
] & constValue[v.type <= 2155])
inline if bool then this.copy(default = Some(Default.Value(value)))
else error("Only values in the range 0 or 1901 to 2155 can be passed to the YEAR type.")
case _ => this.copy(default = Some(Default.Value(value)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ object ColumnTupleConverter:
* The effect type
*/
def convert[Types <: Tuple, F[_]](columnTuples: ColumnTuples[Types, F])(using
converter: ColumnTupleConverter[Types, F]
converter: ColumnTupleConverter[Types, F]
): Tuple.Map[Types, F] =
converter(columnTuples)
15 changes: 10 additions & 5 deletions module/ldbc-codegen/src/main/scala/ldbc/codegen/model/Key.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ object Key:
secondary: Option[SecondaryEngineAttribute]
):

def setSize(value: KeyBlockSize): IndexOption = this.copy(size = Some(value))
def setIndexType(value: IndexType): IndexOption = this.copy(indexType = Some(value))
def setWithParser(value: WithParser): IndexOption = this.copy(parserName = Some(value))
def setComment(value: CommentSet): IndexOption = this.copy(comment = Some(value))
def setEngineAttribute(value: EngineAttribute): IndexOption = this.copy(engine = Some(value))
def setSize(value: KeyBlockSize): IndexOption = this.copy(size = Some(value))

def setIndexType(value: IndexType): IndexOption = this.copy(indexType = Some(value))

def setWithParser(value: WithParser): IndexOption = this.copy(parserName = Some(value))

def setComment(value: CommentSet): IndexOption = this.copy(comment = Some(value))

def setEngineAttribute(value: EngineAttribute): IndexOption = this.copy(engine = Some(value))

def setSecondaryEngineAttribute(value: SecondaryEngineAttribute): IndexOption = this.copy(secondary = Some(value))

def toCode: String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import ldbc.dsl.logging.{ LogEvent, LogHandler }
trait ConnectionProvider[F[_]: Sync]:

private def connection[T](
statement: String,
params: Seq[ParameterBinder[F]],
consumer: ResultSetConsumer[F, T]
statement: String,
params: Seq[ParameterBinder[F]],
consumer: ResultSetConsumer[F, T]
)(using logHandler: LogHandler[F]): Kleisli[F, Connection[F], T] =
Kleisli { connection =>
for
Expand Down
6 changes: 4 additions & 2 deletions module/ldbc-dsl/src/main/scala/ldbc/dsl/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ case class Database[F[_]: Sync](
val release: Connection[F] => F[Unit] = connection => connection.close()
Resource.make(acquire)(release)

def setCharacter(character: Character): Database[F] = this.copy(character = Some(character))
def setCharacter(character: Character): Database[F] = this.copy(character = Some(character))

def setCollate(collate: Collate[String]): Database[F] = this.copy(collate = Some(collate))
def setTables(tables: Set[Table[?]]): Database[F] = this.copy(tables = tables)

def setTables(tables: Set[Table[?]]): Database[F] = this.copy(tables = tables)

/** Functions to manage the processing of connections independently.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ trait CommandSyntax[F[_]: Sync]:
}

def returning[Tag <: Singleton](tag: Tag)(using
mirror: Mirror.ProductOf[P],
index: ValueOf[CoreTuples.IndexOf[mirror.MirroredElemLabels, Tag]],
mirror: Mirror.ProductOf[P],
index: ValueOf[CoreTuples.IndexOf[mirror.MirroredElemLabels, Tag]],
reader: ResultSetReader[
F,
Tuple.Elem[mirror.MirroredElemTypes, CoreTuples.IndexOf[mirror.MirroredElemLabels, Tag]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ trait ConfigLoader[A]:
self =>

def load(config: Config, path: String): A

def map[B](f: A => B): ConfigLoader[B] = (config: Config, path: String) => f(self.load(config, path))

object ConfigLoader:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ object ExecutionContexts:

/** Execution context that runs everything synchronously. This can be useful for testing. */
object synchronous extends ExecutionContext:
def execute(runnable: Runnable): Unit = runnable.run()
def execute(runnable: Runnable): Unit = runnable.run()

def reportFailure(cause: Throwable): Unit = cause.printStackTrace()
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private[ldbc] trait ColumnQuery[F[_], T] extends Column[T]:
def <=>(value: Extract[T])(using parameter: Parameter[F, Extract[T]]): NullSafeEqual[F, T] = nullSafeEqual(value)

def IN(value: Extract[T]*)(using parameter: Parameter[F, Extract[T]]): In[F, T] =
In[F, T](noBagQuotLabel, false, value: _*)
In[F, T](noBagQuotLabel, false, value*)

def BETWEEN(start: Extract[T], end: Extract[T])(using parameter: Parameter[F, Extract[T]]): Between[F, T] =
Between[F, T](noBagQuotLabel, false, start, end)
Expand Down Expand Up @@ -299,7 +299,7 @@ object ColumnQuery:
@targetName("multiColumnNullSafeEqual")
def <=>(value: Extract[T])(using parameter: Parameter[F, Extract[T]]): NullSafeEqual[F, T] = nullSafeEqual(value)

def IN(value: Extract[T]*)(using parameter: Parameter[F, Extract[T]]): In[F, T] = In[F, T](label, false, value: _*)
def IN(value: Extract[T]*)(using parameter: Parameter[F, Extract[T]]): In[F, T] = In[F, T](label, false, value*)

def BETWEEN(start: Extract[T], end: Extract[T])(using parameter: Parameter[F, Extract[T]]): Between[F, T] =
Between[F, T](label, false, start, end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ case class TableQuery[F[_], P <: Product](table: Table[P]) extends Dynamic, Tabl
* A class that implements a [[Product]] that is one-to-one with the table definition.
*/
def join[O <: Product](other: TableQuery[F, O])(
on: TableQuery[F, P] *: Tuple1[TableQuery[F, O]] => ExpressionSyntax[F]
on: TableQuery[F, P] *: Tuple1[TableQuery[F, O]] => ExpressionSyntax[F]
): Join[F, TableQuery[F, P] *: Tuple1[TableQuery[F, O]], TableQuery[F, P] *: Tuple1[TableQuery[F, O]]] =
val main: TableQuery[F, P] = setNameForJoin(this)
val joinTable: TableQuery[F, O] = setNameForJoin(other)
Expand All @@ -98,7 +98,7 @@ case class TableQuery[F[_], P <: Product](table: Table[P]) extends Dynamic, Tabl
* A class that implements a [[Product]] that is one-to-one with the table definition.
*/
def leftJoin[O <: Product](other: TableQuery[F, O])(
on: TableQuery[F, P] *: Tuple1[TableQuery[F, O]] => ExpressionSyntax[F]
on: TableQuery[F, P] *: Tuple1[TableQuery[F, O]] => ExpressionSyntax[F]
): Join[F, TableQuery[F, P] *: Tuple1[TableQuery[F, O]], TableQuery[F, P] *: Tuple1[TableOpt[F, O]]] =
val main: TableQuery[F, P] = setNameForJoin(this)
val joinTable: TableQuery[F, O] = setNameForJoin(other)
Expand All @@ -120,7 +120,7 @@ case class TableQuery[F[_], P <: Product](table: Table[P]) extends Dynamic, Tabl
* A class that implements a [[Product]] that is one-to-one with the table definition.
*/
def rightJoin[O <: Product](other: TableQuery[F, O])(
on: TableQuery[F, P] *: Tuple1[TableQuery[F, O]] => ExpressionSyntax[F]
on: TableQuery[F, P] *: Tuple1[TableQuery[F, O]] => ExpressionSyntax[F]
): Join[F, TableQuery[F, P] *: Tuple1[TableQuery[F, O]], TableOpt[F, P] *: Tuple1[TableQuery[F, O]]] =
val main: TableQuery[F, P] = setNameForJoin(this)
val joinTable: TableQuery[F, O] = setNameForJoin(other)
Expand All @@ -147,7 +147,7 @@ case class TableQuery[F[_], P <: Product](table: Table[P]) extends Dynamic, Tabl
* A list of Tuples constructed with all the property types that Table has.
*/
inline def insert(using mirror: Mirror.ProductOf[P])(
values: mirror.MirroredElemTypes*
values: mirror.MirroredElemTypes*
): Insert[F, P] =
val parameterBinders = values
.flatMap(
Expand Down Expand Up @@ -232,7 +232,7 @@ case class TableQuery[F[_], P <: Product](table: Table[P]) extends Dynamic, Tabl
* A list of Tuples constructed with all the property types that Table has.
*/
inline def insertOrUpdate(using mirror: Mirror.ProductOf[P])(
values: mirror.MirroredElemTypes*
values: mirror.MirroredElemTypes*
): DuplicateKeyUpdateInsert[F] =
val parameterBinders = values
.flatMap(
Expand Down Expand Up @@ -291,9 +291,9 @@ case class TableQuery[F[_], P <: Product](table: Table[P]) extends Dynamic, Tabl
* Scala types that match SQL DataType
*/
inline def update[Tag <: Singleton, T](tag: Tag, value: T)(using
mirror: Mirror.ProductOf[P],
index: ValueOf[CoreTuples.IndexOf[mirror.MirroredElemLabels, Tag]],
check: T =:= Tuple.Elem[mirror.MirroredElemTypes, CoreTuples.IndexOf[mirror.MirroredElemLabels, Tag]]
mirror: Mirror.ProductOf[P],
index: ValueOf[CoreTuples.IndexOf[mirror.MirroredElemLabels, Tag]],
check: T =:= Tuple.Elem[mirror.MirroredElemTypes, CoreTuples.IndexOf[mirror.MirroredElemLabels, Tag]]
): Update[F, P] =
type PARAM = Tuple.Elem[mirror.MirroredElemTypes, CoreTuples.IndexOf[mirror.MirroredElemLabels, Tag]]
val params = List(ParameterBinder[F, PARAM](check(value))(using Parameter.infer[F, PARAM]))
Expand Down
Loading