-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exclude CompositeSupport for scala 3
- Loading branch information
1 parent
f14654d
commit 6fd4690
Showing
12 changed files
with
141 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...kpg/composite/PgCompositeExtensions.scala → ...kpg/composite/PgCompositeExtensions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
core/src/main/scala-3/com/github/tminglei/slickpg/composite/PgCompositeExtensions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.tminglei.slickpg.composite | ||
|
||
import izumi.reflect.macrortti.LightTypeTag | ||
import izumi.reflect.Tag | ||
import slick.jdbc.{JdbcTypesComponent, PostgresProfile} | ||
import scala.annotation.static | ||
import scala.collection.concurrent.TrieMap | ||
import scala.reflect.{classTag, ClassTag} | ||
|
||
trait Struct extends AnyRef | ||
|
||
trait PgCompositeExtensions extends JdbcTypesComponent { driver: PostgresProfile => | ||
//TODO not implemented by now | ||
} |
4 changes: 4 additions & 0 deletions
4
core/src/main/scala-3/com/github/tminglei/slickpg/composite/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Supported Composite type Oper/Functions | ||
--------------------------------------- | ||
|
||
_ps: only type mapper supported currently_ |
68 changes: 68 additions & 0 deletions
68
core/src/main/scala-3/com/github/tminglei/slickpg/utils/TypeConverters.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.github.tminglei.slickpg | ||
package utils | ||
|
||
import izumi.reflect.{Tag => TTag} | ||
import izumi.reflect.macrortti.LightTypeTag | ||
import slick.util.Logging | ||
import java.sql.{Date, Time, Timestamp} | ||
import java.time.{LocalDate, LocalDateTime, LocalTime} | ||
import java.util.UUID | ||
|
||
object TypeConverters extends Logging { | ||
case class ConvConfig(from: LightTypeTag, to: LightTypeTag, var conv: (_ => _)) | ||
|
||
private var convConfigList = List[ConvConfig]() | ||
|
||
// register basic converters | ||
register((v: String) => v.toInt) | ||
register((v: String) => v.toLong) | ||
register((v: String) => v.toShort) | ||
register((v: String) => v.toFloat) | ||
register((v: String) => v.toDouble) | ||
register((v: String) => pgBoolAdjust(v).toBoolean) | ||
register((v: String) => v.toByte) | ||
register((v: String) => UUID.fromString(v)) | ||
// register date/time converters | ||
register((v: String) => Date.valueOf(v)) | ||
register((v: String) => Time.valueOf(v)) | ||
register((v: String) => Timestamp.valueOf(v)) | ||
register((v: Date) => v.toString) | ||
register((v: Time) => v.toString) | ||
register((v: Timestamp) => v.toString) | ||
register((v: String) => LocalDate.parse(v)) | ||
register((v: String) => LocalTime.parse(v)) | ||
register((v: String) => LocalDateTime.parse(v.replace(' ', 'T'))) | ||
register((v: LocalDate) => v.toString) | ||
register((v: LocalTime) => v.toString) | ||
register((v: LocalDateTime) => v.toString) | ||
|
||
def register[FROM, TO](convert: (FROM => TO))(implicit from: TTag[FROM], to: TTag[TO]) = { | ||
logger.info(s"register converter for ${from.tag.repr} => ${to.tag.repr}") | ||
find(from.tag, to.tag).map(_.conv = convert).orElse({ | ||
convConfigList :+= ConvConfig(from.tag, to.tag, convert) | ||
None | ||
}) | ||
} | ||
|
||
def converter[FROM,TO](implicit from: TTag[FROM], to: TTag[TO]): (FROM => TO) = { | ||
find(from.tag, to.tag).map(_.conv.asInstanceOf[(FROM => TO)]) | ||
.getOrElse(throw new IllegalArgumentException(s"Converter NOT FOUND for ${from.tag} => ${to.tag}")) | ||
} | ||
|
||
/// | ||
private def pgBoolAdjust(s: String): String = | ||
Option(s).map(_.toLowerCase) match { | ||
case Some("t") => "true" | ||
case Some("f") => "false" | ||
case _ => s | ||
} | ||
|
||
def find(from: LightTypeTag, to: LightTypeTag): Option[ConvConfig] = { | ||
logger.debug(s"get converter for ${from.repr} => ${to.repr}") | ||
convConfigList.find(e => (e.from =:= from && e.to =:= to)).orElse({ | ||
if (from <:< to) { | ||
Some(ConvConfig(from, to, (v: Any) => v)) | ||
} else None | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
41 changes: 41 additions & 0 deletions
41
src/main/scala-3/com/github/tminglei/slickpg/PgCompositeSupport.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.tminglei.slickpg | ||
|
||
import izumi.reflect.macrortti.LightTypeTag | ||
import izumi.reflect.{Tag => TTag} | ||
|
||
import scala.reflect.{ClassTag, classTag} | ||
import composite.Struct | ||
import slick.jdbc.{PositionedResult, PostgresProfile} | ||
import slick.jdbc.SetParameter | ||
|
||
import scala.deriving.* | ||
import scala.compiletime.{error, erasedValue, summonInline} | ||
|
||
trait PgCompositeSupport extends utils.PgCommonJdbcTypes with array.PgArrayJdbcTypes { driver: PostgresProfile => | ||
|
||
protected lazy val emptyMembersAsNull = true | ||
|
||
//--- | ||
def createCompositeJdbcType[T <: Struct](sqlTypeName: String, cl: ClassLoader = getClass.getClassLoader)(implicit ev: TTag[T], tag: ClassTag[T]): GenericJdbcType[T] = | ||
throw new UnsupportedOperationException("Composite support is unimplemented for scala 3") | ||
|
||
def createCompositeArrayJdbcType[T <: Struct](sqlTypeName: String, cl: ClassLoader = getClass.getClassLoader)(implicit ev: TTag[T], tag: ClassTag[T]): AdvancedArrayJdbcType[T] = | ||
throw new UnsupportedOperationException("Composite support is unimplemented for scala 3") | ||
|
||
/// Plain SQL support | ||
def nextComposite[T <: Struct](r: PositionedResult, cl: ClassLoader = getClass.getClassLoader)(implicit ev: TTag[T], tag: ClassTag[T]) = | ||
throw new UnsupportedOperationException("Composite support is unimplemented for scala 3") | ||
def nextCompositeArray[T <: Struct](r: PositionedResult, cl: ClassLoader = getClass.getClassLoader)(implicit ev: TTag[T], tag: ClassTag[T]) = | ||
throw new UnsupportedOperationException("Composite support is unimplemented for scala 3") | ||
|
||
def createCompositeSetParameter[T <: Struct](sqlTypeName: String, cl: ClassLoader = getClass.getClassLoader)(implicit ev: TTag[T], tag: ClassTag[T]) = | ||
throw new UnsupportedOperationException("Composite support is unimplemented for scala 3") | ||
|
||
def createCompositeOptionSetParameter[T <: Struct](sqlTypeName: String, cl: ClassLoader = getClass.getClassLoader)(implicit ev: TTag[T], tag: ClassTag[T]) = | ||
throw new UnsupportedOperationException("Composite support is unimplemented for scala 3") | ||
def createCompositeArraySetParameter[T <: Struct](sqlTypeName: String, cl: ClassLoader = getClass.getClassLoader)(implicit ev: TTag[T], tag: ClassTag[T]) = { | ||
throw new UnsupportedOperationException("Composite support is unimplemented for scala 3") | ||
} | ||
def createCompositeOptionArraySetParameter[T <: Struct](sqlTypeName: String, cl: ClassLoader = getClass.getClassLoader)(implicit ev: TTag[T], tag: ClassTag[T]) = | ||
throw new UnsupportedOperationException("Composite support is unimplemented for scala 3") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.