<commit_before>package com.github.tminglei.slickpg
package array

import scala.reflect.ClassTag
import java.util.{Map => JMap}
import scala.slick.driver.{PostgresDriver, JdbcTypesComponent}
import java.sql.{ResultSet, PreparedStatement}

trait PgArrayJdbcTypes extends JdbcTypesComponent { driver: PostgresDriver =>

  class SimpleArrayListJdbcType[T](sqlBaseType: String)(
              implicit override val classTag: ClassTag[List[T]], tag: ClassTag[T])
                    extends DriverJdbcType[List[T]] {

    override def sqlType: Int = java.sql.Types.ARRAY

    override def sqlTypeName: String = s"$sqlBaseType ARRAY"

    override def getValue(r: ResultSet, idx: Int): List[T] = {
      val value = r.getArray(idx)
      if (r.wasNull) null else value.getArray.asInstanceOf[Array[Any]].map(_.asInstanceOf[T]).toList
    }

    override def setValue(vList: List[T], p: PreparedStatement, idx: Int): Unit = p.setArray(idx, mkArray(vList))

    override def updateValue(vList: List[T], r: ResultSet, idx: Int): Unit = r.updateArray(idx, mkArray(vList))

    override def hasLiteralForm: Boolean = false

    override def valueToSQLLiteral(vList: List[T]) = if(vList eq null) "NULL" else s"'${buildArrayStr(vList)}'"

    ///
    def basedOn[U](tmap: T => U, tcomap: U => T): DriverJdbcType[List[T]] =
      new SimpleArrayListJdbcType[T](sqlBaseType) {

        override def getValue(r: ResultSet, idx: Int): List[T] = {
          val value = r.getArray(idx)
          if (r.wasNull) null else value.getArray.asInstanceOf[Array[Any]]
            .map(e => tcomap(e.asInstanceOf[U])).toList
        }

        //--
        override protected def buildArrayStr(v: List[Any]): String = super.buildArrayStr(v.map(e => tmap(e.asInstanceOf[T])))
      }

    //--
    private def mkArray(v: List[T]): java.sql.Array = new SimpleArray(sqlBaseType, v, buildArrayStr)

    protected def buildArrayStr(vList: List[Any]): String = utils.SimpleArrayUtils.mkString[Any](_.toString)(vList)
  }

  ///-- can be used to map complex composite/nested array
  class AdvancedArrayListJdbcType[T](sqlBaseType: String, fromString: (String => List[T]), mkString: (List[T] => String))(
              implicit override val classTag: ClassTag[List[T]], tag: ClassTag[T])
                    extends DriverJdbcType[List[T]] {

    override def sqlType: Int = java.sql.Types.ARRAY
<commit_msg>add alias `NestedArrayListJdbcType` for `AdvancedArrayListJdbcType` to keep back compatible<commit_after>package com.github.tminglei.slickpg
package array

import scala.reflect.ClassTag
import java.util.{Map => JMap}
import scala.slick.driver.{PostgresDriver, JdbcTypesComponent}
import java.sql.{ResultSet, PreparedStatement}

trait PgArrayJdbcTypes extends JdbcTypesComponent { driver: PostgresDriver =>

  class SimpleArrayListJdbcType[T](sqlBaseType: String)(
              implicit override val classTag: ClassTag[List[T]], tag: ClassTag[T])
                    extends DriverJdbcType[List[T]] {

    override def sqlType: Int = java.sql.Types.ARRAY

    override def sqlTypeName: String = s"$sqlBaseType ARRAY"

    override def getValue(r: ResultSet, idx: Int): List[T] = {
      val value = r.getArray(idx)
      if (r.wasNull) null else value.getArray.asInstanceOf[Array[Any]].map(_.asInstanceOf[T]).toList
    }

    override def setValue(vList: List[T], p: PreparedStatement, idx: Int): Unit = p.setArray(idx, mkArray(vList))

    override def updateValue(vList: List[T], r: ResultSet, idx: Int): Unit = r.updateArray(idx, mkArray(vList))

    override def hasLiteralForm: Boolean = false

    override def valueToSQLLiteral(vList: List[T]) = if(vList eq null) "NULL" else s"'${buildArrayStr(vList)}'"

    ///
    def basedOn[U](tmap: T => U, tcomap: U => T): DriverJdbcType[List[T]] =
      new SimpleArrayListJdbcType[T](sqlBaseType) {

        override def getValue(r: ResultSet, idx: Int): List[T] = {
          val value = r.getArray(idx)
          if (r.wasNull) null else value.getArray.asInstanceOf[Array[Any]]
            .map(e => tcomap(e.asInstanceOf[U])).toList
        }

        //--
        override protected def buildArrayStr(v: List[Any]): String = super.buildArrayStr(v.map(e => tmap(e.asInstanceOf[T])))
      }

    //--
    private def mkArray(v: List[T]): java.sql.Array = new SimpleArray(sqlBaseType, v, buildArrayStr)

    protected def buildArrayStr(vList: List[Any]): String = utils.SimpleArrayUtils.mkString[Any](_.toString)(vList)
  }

  ///-- can be used to map complex composite/nested array
  @deprecated /* alias, added for back compatible */
  type NestedArrayListJdbcType[T] = AdvancedArrayListJdbcType[T]

  class AdvancedArrayListJdbcType[T](sqlBaseType: String,
                                  fromString: (String => List[T]),
                                  mkString: (List[T] => String))(
              implicit override val classTag: ClassTag[List[T]], tag: ClassTag[T])
                    extends DriverJdbcType[List[T]] {

    override def sqlType: Int = java.sql.Types.ARRAY

{'fraction_non_alphanumeric': 0.12796965462168097, 'fraction_numerical': 0.0, 'mean_word_length': 3.489247311827957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1795569', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1575, 'n_words': 371}