Skip to content

Commit

Permalink
Merge pull request #68 from takapi327/refactor/2023-10-Character-code…
Browse files Browse the repository at this point in the history
…-modification

Refactor/2023 10 character code modification
  • Loading branch information
takapi327 authored Oct 20, 2023
2 parents e556fe2 + 65c9e47 commit 4ade67d
Show file tree
Hide file tree
Showing 10 changed files with 953 additions and 228 deletions.
2 changes: 0 additions & 2 deletions core/src/main/scala/ldbc/core/Alias.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ private[ldbc] trait Alias:
def VISIBLE[T]: Visible[T] = Visible[T]()
def INVISIBLE[T]: InVisible[T] = InVisible[T]()

def COLLATE[T <: String | Option[String]](name: String): Collate & Attribute[T] = new Collate(name) with Attribute[T]

object COLUMN_FORMAT:
def FIXED[T]: ColumnFormat.Fixed[T] = ColumnFormat.Fixed[T]()
def DYNAMIC[T]: ColumnFormat.Dynamic[T] = ColumnFormat.Dynamic[T]()
Expand Down
831 changes: 823 additions & 8 deletions core/src/main/scala/ldbc/core/Character.scala

Large diffs are not rendered by default.

202 changes: 38 additions & 164 deletions core/src/main/scala/ldbc/core/DataType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ object DataType:

def character: Option[Character]

def collate: Option[Collate]
def collate: Option[Collate[T]]

/** SQL DataType to represent BLOB type of string data trait.
*
Expand Down Expand Up @@ -618,9 +618,9 @@ object DataType:
private[ldbc] case class CChar[T <: String | Option[String]](
length: Int,
isOptional: Boolean,
default: Option[Default] = None,
character: Option[Character] = None,
collate: Option[Collate] = None
default: Option[Default] = None,
character: Option[Character] = None,
collate: Option[Collate[T]] = None
) extends StringType[T]:

override def typeName: String = s"CHAR($length)"
Expand Down Expand Up @@ -648,26 +648,12 @@ object DataType:
*/
def CHARACTER_SET(character: Character): CChar[T] = this.copy(character = Some(character))

/** Method for setting Character Set to DataType in SQL.
*
* @param character
* Character Set
*/
def CHARACTER_SET(character: String): CChar[T] = CHARACTER_SET(Character(character))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: Collate): CChar[T] = this.copy(collate = Some(collate))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: String): CChar[T] = COLLATE(Collate(collate))
def COLLATE(collate: Collate[T]): CChar[T] = this.copy(collate = Some(collate))

/** Model for representing the Varchar data type, which is the string data of SQL DataType.
*
Expand All @@ -687,9 +673,9 @@ object DataType:
private[ldbc] case class Varchar[T <: String | Option[String]](
length: Int,
isOptional: Boolean,
default: Option[Default] = None,
character: Option[Character] = None,
collate: Option[Collate] = None
default: Option[Default] = None,
character: Option[Character] = None,
collate: Option[Collate[T]] = None
) extends StringType[T]:

override def typeName: String = s"VARCHAR($length)"
Expand Down Expand Up @@ -717,26 +703,12 @@ object DataType:
*/
def CHARACTER_SET(character: Character): Varchar[T] = this.copy(character = Some(character))

/** Method for setting Character Set to DataType in SQL.
*
* @param character
* Character Set
*/
def CHARACTER_SET(character: String): Varchar[T] = CHARACTER_SET(Character(character))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: Collate): Varchar[T] = this.copy(collate = Some(collate))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: String): Varchar[T] = COLLATE(Collate(collate))
def COLLATE(collate: Collate[T]): Varchar[T] = this.copy(collate = Some(collate))

/** Model for representing the Binary data type, which is the string data of SQL DataType.
*
Expand All @@ -756,9 +728,9 @@ object DataType:
private[ldbc] case class Binary[T <: Array[Byte] | Option[Array[Byte]]](
length: Int,
isOptional: Boolean,
default: Option[Default] = None,
character: Option[Character] = None,
collate: Option[Collate] = None
default: Option[Default] = None,
character: Option[Character] = None,
collate: Option[Collate[T]] = None
) extends StringType[T]:

override def typeName: String = s"BINARY($length)"
Expand Down Expand Up @@ -786,26 +758,12 @@ object DataType:
*/
def CHARACTER_SET(character: Character): Binary[T] = this.copy(character = Some(character))

/** Method for setting Character Set to DataType in SQL.
*
* @param character
* Character Set
*/
def CHARACTER_SET(character: String): Binary[T] = CHARACTER_SET(Character(character))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: Collate): Binary[T] = this.copy(collate = Some(collate))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: String): Binary[T] = COLLATE(Collate(collate))
def COLLATE(collate: Collate[T]): Binary[T] = this.copy(collate = Some(collate))

/** Model for representing the Varbinary data type, which is the string data of SQL DataType.
*
Expand All @@ -825,9 +783,9 @@ object DataType:
private[ldbc] case class Varbinary[T <: Array[Byte] | Option[Array[Byte]]](
length: Int,
isOptional: Boolean,
default: Option[Default] = None,
character: Option[Character] = None,
collate: Option[Collate] = None
default: Option[Default] = None,
character: Option[Character] = None,
collate: Option[Collate[T]] = None
) extends StringType[T]:

override def typeName: String = s"VARBINARY($length)"
Expand Down Expand Up @@ -855,26 +813,12 @@ object DataType:
*/
def CHARACTER_SET(character: Character): Varbinary[T] = this.copy(character = Some(character))

/** Method for setting Character Set to DataType in SQL.
*
* @param character
* Character Set
*/
def CHARACTER_SET(character: String): Varbinary[T] = CHARACTER_SET(Character(character))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: Collate): Varbinary[T] = this.copy(collate = Some(collate))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: String): Varbinary[T] = COLLATE(Collate(collate))
def COLLATE(collate: Collate[T]): Varbinary[T] = this.copy(collate = Some(collate))

/** Model for representing the Tinyblob data type, which is the string data of SQL DataType.
*
Expand Down Expand Up @@ -1014,9 +958,9 @@ object DataType:
*/
private[ldbc] case class TinyText[T <: String | Option[String]](
isOptional: Boolean,
character: Option[Character] = None,
collate: Option[Collate] = None,
default: Option[Default] = None
character: Option[Character] = None,
collate: Option[Collate[T]] = None,
default: Option[Default] = None
) extends StringType[T]:

override def typeName: String = "TINYTEXT"
Expand All @@ -1035,26 +979,12 @@ object DataType:
*/
def CHARACTER_SET(character: Character): TinyText[T] = this.copy(character = Some(character))

/** Method for setting Character Set to DataType in SQL.
*
* @param character
* Character Set
*/
def CHARACTER_SET(character: String): TinyText[T] = CHARACTER_SET(Character(character))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: Collate): TinyText[T] = this.copy(collate = Some(collate))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: String): TinyText[T] = COLLATE(Collate(collate))
def COLLATE(collate: Collate[T]): TinyText[T] = this.copy(collate = Some(collate))

/** Method for setting Default value to DataType in SQL.
*
Expand All @@ -1081,9 +1011,9 @@ object DataType:
*/
private[ldbc] case class Text[T <: String | Option[String]](
isOptional: Boolean,
character: Option[Character] = None,
collate: Option[Collate] = None,
default: Option[Default] = None
character: Option[Character] = None,
collate: Option[Collate[T]] = None,
default: Option[Default] = None
) extends StringType[T]:

override def typeName: String = "TEXT"
Expand All @@ -1102,26 +1032,12 @@ object DataType:
*/
def CHARACTER_SET(character: Character): Text[T] = this.copy(character = Some(character))

/** Method for setting Character Set to DataType in SQL.
*
* @param character
* Character Set
*/
def CHARACTER_SET(character: String): Text[T] = CHARACTER_SET(Character(character))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: Collate): Text[T] = this.copy(collate = Some(collate))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: String): Text[T] = COLLATE(Collate(collate))
def COLLATE(collate: Collate[T]): Text[T] = this.copy(collate = Some(collate))

/** Method for setting Default value to DataType in SQL.
*
Expand All @@ -1148,9 +1064,9 @@ object DataType:
*/
private[ldbc] case class MediumText[T <: String | Option[String]](
isOptional: Boolean,
character: Option[Character] = None,
collate: Option[Collate] = None,
default: Option[Default] = None
character: Option[Character] = None,
collate: Option[Collate[T]] = None,
default: Option[Default] = None
) extends StringType[T]:

override def typeName: String = "MEDIUMTEXT"
Expand All @@ -1169,26 +1085,12 @@ object DataType:
*/
def CHARACTER_SET(character: Character): MediumText[T] = this.copy(character = Some(character))

/** Method for setting Character Set to DataType in SQL.
*
* @param character
* Character Set
*/
def CHARACTER_SET(character: String): MediumText[T] = CHARACTER_SET(Character(character))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: Collate): MediumText[T] = this.copy(collate = Some(collate))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: String): MediumText[T] = COLLATE(Collate(collate))
def COLLATE(collate: Collate[T]): MediumText[T] = this.copy(collate = Some(collate))

/** Method for setting Default value to DataType in SQL.
*
Expand All @@ -1215,9 +1117,9 @@ object DataType:
*/
private[ldbc] case class LongText[T <: String | Option[String]](
isOptional: Boolean,
character: Option[Character] = None,
collate: Option[Collate] = None,
default: Option[Default] = None
character: Option[Character] = None,
collate: Option[Collate[T]] = None,
default: Option[Default] = None
) extends StringType[T]:

override def typeName: String = "LONGTEXT"
Expand All @@ -1236,26 +1138,12 @@ object DataType:
*/
def CHARACTER_SET(character: Character): LongText[T] = this.copy(character = Some(character))

/** Method for setting Character Set to DataType in SQL.
*
* @param character
* Character Set
*/
def CHARACTER_SET(character: String): LongText[T] = CHARACTER_SET(Character(character))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: Collate): LongText[T] = this.copy(collate = Some(collate))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: String): LongText[T] = COLLATE(Collate(collate))
def COLLATE(collate: Collate[T]): LongText[T] = this.copy(collate = Some(collate))

/** Method for setting Default value to DataType in SQL.
*
Expand All @@ -1276,11 +1164,11 @@ object DataType:
* @tparam T
* Scala types that match SQL DataType
*/
private[ldbc] case class Enum[T <: EnumModel | Option[?]](
private[ldbc] case class Enum[T <: EnumModel | Option[EnumModel]](
isOptional: Boolean,
character: Option[Character] = None,
collate: Option[Collate] = None,
default: Option[Default] = None
character: Option[Character] = None,
collate: Option[Collate[T]] = None,
default: Option[Default] = None
)(using enumDataType: EnumDataType[?])
extends DataType[T]:

Expand All @@ -1300,26 +1188,12 @@ object DataType:
*/
def CHARACTER_SET(character: Character): Enum[T] = this.copy(character = Some(character))

/** Method for setting Character Set to DataType in SQL.
*
* @param character
* Character Set
*/
def CHARACTER_SET(character: String): Enum[T] = CHARACTER_SET(Character(character))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: Collate): Enum[T] = this.copy(collate = Some(collate))

/** Method for setting Collation to DataType in SQL.
*
* @param collate
* Collation
*/
def COLLATE(collate: String): Enum[T] = COLLATE(Collate(collate))
def COLLATE(collate: Collate[T]): Enum[T] = this.copy(collate = Some(collate))

/** Method for setting Default value to DataType in SQL.
*
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/ldbc/core/DataTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ trait DataTypes:

inline def LONGTEXT[T <: String | Option[String]](): LongText[T] = LongText(isOptional[T])

inline def ENUM[T <: EnumModel | Option[?]](using EnumDataType[?]): Enum[T] = Enum(isOptional[T])
inline def ENUM[T <: EnumModel | Option[EnumModel]](using EnumDataType[?]): Enum[T] = Enum(isOptional[T])

/** ===== List of Date Data Types ===== */

Expand Down
Loading

0 comments on commit 4ade67d

Please sign in to comment.