Skip to content

Commit

Permalink
Action sbt scalafmtAll
Browse files Browse the repository at this point in the history
  • Loading branch information
takapi327 committed Oct 22, 2023
1 parent 3961038 commit a49c7cc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
27 changes: 19 additions & 8 deletions core/src/main/scala/ldbc/core/DataType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ object DataType:
*/
sealed trait DateType[
T <: Short | Instant | OffsetTime | LocalTime | LocalDate | LocalDateTime | OffsetDateTime | ZonedDateTime | JYear |
Option[Short | Instant | OffsetTime | LocalTime | LocalDate | LocalDateTime | OffsetDateTime | ZonedDateTime | JYear]
Option[
Short | Instant | OffsetTime | LocalTime | LocalDate | LocalDateTime | OffsetDateTime | ZonedDateTime | JYear
]
] extends DataType[T]

/** ===== List of Numeric Data Types ===== */
Expand Down Expand Up @@ -1360,11 +1362,17 @@ object DataType:
*/
inline def DEFAULT(value: T | 0 | String): Time[T] =
inline erasedValue[value.type] match
case _: Option[?] => this.copy(default = Some(value.asInstanceOf[Option[?]].fold(Default.Null)(Default.Value(_))))
case _: Option[?] =>
this.copy(default = Some(value.asInstanceOf[Option[?]].fold(Default.Null)(Default.Value(_))))
case v: String =>
inline if constValue[Matches[v.type, """^(-?8[0-3][0-8]|-?[0-7][0-9]{2}|0?[0-9]{1,2}):([0-5]\d):([0-5]\d)$"""]] then
this.copy(default = Some(Default.Value(value)))
else error("A string in hh:mm:ss or hhh:mm:ss format and in the range from '-838:59:59' to '838:59:59' must be passed to the TIME type.")
inline if constValue[
Matches[v.type, """^(-?8[0-3][0-8]|-?[0-7][0-9]{2}|0?[0-9]{1,2}):([0-5]\d):([0-5]\d)$"""]
]
then this.copy(default = Some(Default.Value(value)))
else
error(
"A string in hh:mm:ss or hhh:mm:ss format and in the range from '-838:59:59' to '838:59:59' must be passed to the TIME type."
)
case _: LocalTime => this.copy(default = Some(Default.Value(value)))

/** This model is used to represent SQL DataType Year data.
Expand Down Expand Up @@ -1400,10 +1408,13 @@ object DataType:
*/
inline def DEFAULT(value: T | Int): Year[T] =
inline erasedValue[value.type] match
case _: Option[?] => this.copy(default = Some(value.asInstanceOf[Option[?]].fold(Default.Null)(Default.Value(_))))
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)))
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)))
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
7 changes: 5 additions & 2 deletions core/src/main/scala/ldbc/core/DataTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ trait DataTypes:

inline def DATE[T <: LocalDate | Option[LocalDate]]: Date[T] = Date(isOptional[T])

inline def DATETIME[T <: Instant | LocalDateTime | OffsetTime | Option[Instant | LocalDateTime | OffsetTime]]: DateTime[T] =
inline def DATETIME[T <: Instant | LocalDateTime | OffsetTime | Option[Instant | LocalDateTime | OffsetTime]]
: DateTime[T] =
DateTime(None, isOptional[T])

inline def DATETIME[T <: Instant | LocalDateTime | OffsetTime | Option[Instant | LocalDateTime | OffsetTime]](
Expand All @@ -174,7 +175,9 @@ trait DataTypes:
"As of MySQL 8.0.19, specifying the number of digits for the YEAR data type is deprecated. It will not be supported in future MySQL versions.",
"Ldbc-Core 0.1.0"
)
inline def YEAR[T <: Int | Instant | LocalDate | JYear | Option[Int | Instant | LocalDate | JYear]](digit: 4): Year[T] =
inline def YEAR[T <: Int | Instant | LocalDate | JYear | Option[Int | Instant | LocalDate | JYear]](
digit: 4
): Year[T] =
Year(Some(digit), isOptional[T])

inline def YEAR[T <: Int | Instant | LocalDate | JYear | Option[Int | Instant | LocalDate | JYear]]: Year[T] =
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/ldbc/core/Default.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object Default:

override def queryString: String = _value match
case _: Boolean | Short | Int | Long | Double => s"DEFAULT $value"
case _ => s"DEFAULT '$value'"
case _ => s"DEFAULT '$value'"

/** Model for setting TimeStamp-specific Default values.
*
Expand Down
12 changes: 4 additions & 8 deletions core/src/test/scala/ldbc/core/DataTypesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ class DataTypesTest extends AnyFlatSpec:
}

it should "A string in hh:mm:ss or hhh:mm:ss format and in the range from '-838:59:59' to '838:59:59' must be passed to the TIME type." in {
assertCompiles(
"""
assertCompiles("""
import ldbc.core.*
import ldbc.core.DataType.*
Expand All @@ -423,8 +422,7 @@ class DataTypesTest extends AnyFlatSpec:
}

it should "Passing a string of type TIME in hh:mm:ss or hhh:mm:ss format other than the range from '-838:59:59' to '838:59:59' will result in a compile error." in {
assertDoesNotCompile(
"""
assertDoesNotCompile("""
import ldbc.core.*
import ldbc.core.DataType.*
Expand All @@ -435,8 +433,7 @@ class DataTypesTest extends AnyFlatSpec:
}

it should "The default value can be passed to the YEAR type as 0 or a value greater than or equal to 1901 or less than or equal to 2155." in {
assertCompiles(
"""
assertCompiles("""
import ldbc.core.*
import ldbc.core.DataType.*
Expand All @@ -447,8 +444,7 @@ class DataTypesTest extends AnyFlatSpec:
}

it should "If a value other than 0 or a value in the range 1901-2155 is passed, a default value of type Year will result in an error." in {
assertDoesNotCompile(
"""
assertDoesNotCompile("""
import ldbc.core.*
import ldbc.core.DataType.*
Expand Down

0 comments on commit a49c7cc

Please sign in to comment.