Skip to content

Commit

Permalink
array of domain types is apparently broken, need to fix that soon.
Browse files Browse the repository at this point in the history
 followup ddc4e7b
  • Loading branch information
oyvindberg committed Sep 1, 2023
1 parent d37bf07 commit a4fd90e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 66 deletions.
13 changes: 5 additions & 8 deletions sql/custom/comments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ select c.table_schema,
c.column_name,
pgd.description
from pg_catalog.pg_statio_all_tables as st
inner join pg_catalog.pg_description pgd on (
pgd.objoid = st.relid
)
inner join information_schema.columns c on (
pgd.objsubid = c.ordinal_position and
c.table_schema = st.schemaname and
c.table_name = st.relname
)
inner join pg_catalog.pg_description pgd on pgd.objoid = st.relid
inner join information_schema.columns c
on pgd.objsubid = c.ordinal_position
and c.table_schema = st.schemaname
and c.table_name = st.relname
8 changes: 4 additions & 4 deletions sql/custom/constraints.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
with cols as (SELECT nc.nspname::information_schema.sql_identifier AS table_schema,
c.relname::information_schema.sql_identifier AS table_name,
a.attname::information_schema.sql_identifier AS column_name,
a.attnum::information_schema.cardinal_number AS ordinal_position
with cols as (SELECT nc.nspname AS table_schema,
c.relname AS table_name,
a.attname AS column_name,
a.attnum AS ordinal_position
FROM pg_attribute a
LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
JOIN (pg_class c JOIN pg_namespace nc ON c.relnamespace = nc.oid) ON a.attrelid = c.oid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ object CommentsSqlRepoImpl extends CommentsSqlRepo {
c.column_name,
pgd.description
from pg_catalog.pg_statio_all_tables as st
inner join pg_catalog.pg_description pgd on (
pgd.objoid = st.relid
)
inner join information_schema.columns c on (
pgd.objsubid = c.ordinal_position and
c.table_schema = st.schemaname and
c.table_name = st.relname
)"""
inner join pg_catalog.pg_description pgd on pgd.objoid = st.relid
inner join information_schema.columns c
on pgd.objsubid = c.ordinal_position
and c.table_schema = st.schemaname
and c.table_name = st.relname
"""
sql.as(CommentsSqlRow.rowParser(1).*)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import java.sql.Connection
object ConstraintsSqlRepoImpl extends ConstraintsSqlRepo {
override def apply()(implicit c: Connection): List[ConstraintsSqlRow] = {
val sql =
SQL"""with cols as (SELECT nc.nspname::information_schema.sql_identifier AS table_schema,
c.relname::information_schema.sql_identifier AS table_name,
a.attname::information_schema.sql_identifier AS column_name,
a.attnum::information_schema.cardinal_number AS ordinal_position
SQL"""with cols as (SELECT nc.nspname AS table_schema,
c.relname AS table_name,
a.attname AS column_name,
a.attnum AS ordinal_position
FROM pg_attribute a
LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
JOIN (pg_class c JOIN pg_namespace nc ON c.relnamespace = nc.oid) ON a.attrelid = c.oid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import play.api.libs.json.Reads
import play.api.libs.json.Writes
import scala.collection.immutable.ListMap
import scala.util.Try
import typo.generated.information_schema.SqlIdentifier

case class ConstraintsSqlRow(
/** Points to [[information_schema.table_constraints.TableConstraintsViewRow.tableSchema]]
Expand All @@ -30,8 +29,8 @@ case class ConstraintsSqlRow(
/** Points to [[information_schema.table_constraints.TableConstraintsViewRow.tableName]]
debug: {"baseColumnName":"table_name","baseRelationName":"information_schema.table_constraints","columnClassName":"java.lang.String","columnDisplaySize":2147483647,"parsedColumnName":{"name":"table_name"},"columnName":"table_name","columnType":"VarChar","columnTypeName":"name","format":0,"isAutoIncrement":false,"isCaseSensitive":true,"isCurrency":false,"isDefinitelyWritable":false,"isNullable":"Nullable","isReadOnly":false,"isSearchable":true,"isSigned":false,"isWritable":true,"precision":2147483647,"scale":0,"tableName":"table_constraints"} */
tableName: Option[/* nullability unknown */ String],
/** debug: {"columnClassName":"java.sql.Array","columnDisplaySize":2147483647,"parsedColumnName":{"name":"columns"},"columnName":"columns","columnType":"Array","columnTypeName":"\"information_schema\".\"_sql_identifier\"","format":0,"isAutoIncrement":false,"isCaseSensitive":true,"isCurrency":false,"isDefinitelyWritable":false,"isNullable":"NullableUnknown","isReadOnly":false,"isSearchable":true,"isSigned":false,"isWritable":true,"precision":2147483647,"scale":0} */
columns: /* nullability unknown */ Option[Array[SqlIdentifier]],
/** debug: {"columnClassName":"java.sql.Array","columnDisplaySize":2147483647,"parsedColumnName":{"name":"columns"},"columnName":"columns","columnType":"Array","columnTypeName":"_name","format":0,"isAutoIncrement":false,"isCaseSensitive":true,"isCurrency":false,"isDefinitelyWritable":false,"isNullable":"NullableUnknown","isReadOnly":false,"isSearchable":true,"isSigned":false,"isWritable":true,"precision":2147483647,"scale":0} */
columns: /* nullability unknown */ Option[Array[String]],
/** Points to [[information_schema.table_constraints.TableConstraintsViewRow.constraintName]]
debug: {"baseColumnName":"constraint_name","baseRelationName":"information_schema.table_constraints","columnClassName":"java.lang.String","columnDisplaySize":2147483647,"parsedColumnName":{"name":"constraint_name"},"columnName":"constraint_name","columnType":"VarChar","columnTypeName":"name","format":0,"isAutoIncrement":false,"isCaseSensitive":true,"isCurrency":false,"isDefinitelyWritable":false,"isNullable":"Nullable","isReadOnly":false,"isSearchable":true,"isSigned":false,"isWritable":true,"precision":2147483647,"scale":0,"tableName":"table_constraints"} */
constraintName: Option[/* nullability unknown */ String],
Expand All @@ -46,7 +45,7 @@ object ConstraintsSqlRow {
ConstraintsSqlRow(
tableSchema = json.\("table_schema").toOption.map(_.as(Reads.StringReads)),
tableName = json.\("table_name").toOption.map(_.as(Reads.StringReads)),
columns = json.\("columns").toOption.map(_.as(Reads.ArrayReads[SqlIdentifier](SqlIdentifier.reads, implicitly))),
columns = json.\("columns").toOption.map(_.as(Reads.ArrayReads[String](Reads.StringReads, implicitly))),
constraintName = json.\("constraint_name").toOption.map(_.as(Reads.StringReads)),
checkClause = json.\("check_clause").toOption.map(_.as(Reads.StringReads))
)
Expand All @@ -58,7 +57,7 @@ object ConstraintsSqlRow {
ConstraintsSqlRow(
tableSchema = row(idx + 0)(Column.columnToOption(Column.columnToString)),
tableName = row(idx + 1)(Column.columnToOption(Column.columnToString)),
columns = row(idx + 2)(Column.columnToOption(SqlIdentifier.arrayColumn)),
columns = row(idx + 2)(Column.columnToOption(Column.columnToArray[String](Column.columnToString, implicitly))),
constraintName = row(idx + 3)(Column.columnToOption(Column.columnToString)),
checkClause = row(idx + 4)(Column.columnToOption(Column.columnToString))
)
Expand All @@ -68,7 +67,7 @@ object ConstraintsSqlRow {
new JsObject(ListMap[String, JsValue](
"table_schema" -> Writes.OptionWrites(Writes.StringWrites).writes(o.tableSchema),
"table_name" -> Writes.OptionWrites(Writes.StringWrites).writes(o.tableName),
"columns" -> Writes.OptionWrites(Writes.arrayWrites[SqlIdentifier](implicitly, SqlIdentifier.writes)).writes(o.columns),
"columns" -> Writes.OptionWrites(Writes.arrayWrites[String](implicitly, Writes.StringWrites)).writes(o.columns),
"constraint_name" -> Writes.OptionWrites(Writes.StringWrites).writes(o.constraintName),
"check_clause" -> Writes.OptionWrites(Writes.StringWrites).writes(o.checkClause)
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import play.api.libs.json.Writes
case class TypoOffsetDateTime(value: OffsetDateTime)

object TypoOffsetDateTime {
val parser: DateTimeFormatter =
new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss").appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true).appendPattern("X").toFormatter
val parser: DateTimeFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss").appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true).appendPattern("X").toFormatter
def apply(value: OffsetDateTime): TypoOffsetDateTime = new TypoOffsetDateTime(value.truncatedTo(ChronoUnit.MICROS))
def now = TypoOffsetDateTime(OffsetDateTime.now)
implicit lazy val arrayColumn: Column[Array[TypoOffsetDateTime]] = Column.nonNull[Array[TypoOffsetDateTime]]((v1: Any, _) =>
Expand Down

This file was deleted.

0 comments on commit a4fd90e

Please sign in to comment.