Skip to content

Commit

Permalink
Support nested catListTable (by represented nested arrays as text)
Browse files Browse the repository at this point in the history
This is one possible "fix" to #168. With this `catListTable` arbitrarily deep trees of `ListTable`s.

It comes at a relatively high cost, however.

Currently we represent nested arrays with anonymous records. This works reasonably well, except that we can't extract the field from the anonymous record when we need it (PostgreSQL [theoretically](https://www.postgresql.org/docs/13/release-13.html#id-1.11.6.16.5.6) suports `.f1` syntax since PG13 but it only works in very limited situations). But it does mean we can decode the results using Hasql's binary decoders, and ordering works how we expect ('array[row(array[9])] < array[row(array[10])]'.

What this PR does is instead represent nested arrays as text. To be able to decoder this, we need each 'DBType' to supply a text parser in addition to a binary decoder. It also means that ordering is no longer intuitive, because `array[array[9]::text] > array[array[10]::text]`. However, it does mean we can nest `catListTable`s to our heart's content and it will always just work.
  • Loading branch information
shane-circuithub committed Aug 15, 2023
1 parent 9e7a447 commit 971d4d6
Show file tree
Hide file tree
Showing 13 changed files with 601 additions and 91 deletions.
7 changes: 7 additions & 0 deletions rel8.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ source-repository head
library
build-depends:
aeson
, attoparsec
, base ^>= 4.14 || ^>=4.15 || ^>=4.16 || ^>=4.17
, base16
, base-compat ^>= 0.11 || ^>= 0.12 || ^>= 0.13
, bifunctors
, bytestring
Expand All @@ -40,6 +42,7 @@ library
, these
, time
, transformers
, utf8-string
, uuid
, vector
default-language:
Expand Down Expand Up @@ -201,6 +204,7 @@ library
Rel8.Type
Rel8.Type.Array
Rel8.Type.Composite
Rel8.Type.Decoder
Rel8.Type.Eq
Rel8.Type.Enum
Rel8.Type.Information
Expand All @@ -210,6 +214,9 @@ library
Rel8.Type.Name
Rel8.Type.Num
Rel8.Type.Ord
Rel8.Type.Parser
Rel8.Type.Parser.ByteString
Rel8.Type.Parser.Time
Rel8.Type.ReadShow
Rel8.Type.Semigroup
Rel8.Type.String
Expand Down
7 changes: 4 additions & 3 deletions src/Rel8/Expr/Serialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
import Rel8.Expr.Opaleye ( scastExpr )
import Rel8.Schema.Null ( Unnullify, Nullity( Null, NotNull ), Sql, nullable )
import Rel8.Type ( DBType, typeInformation )
import Rel8.Type.Decoder (Decoder (..))
import Rel8.Type.Information ( TypeInformation(..) )


Expand All @@ -44,6 +45,6 @@ slitExpr nullity info@TypeInformation {encode} =


sparseValue :: Nullity a -> TypeInformation (Unnullify a) -> Hasql.Row a
sparseValue nullity TypeInformation {decode} = case nullity of
Null -> Hasql.column $ Hasql.nullable decode
NotNull -> Hasql.column $ Hasql.nonNullable decode
sparseValue nullity TypeInformation {decode = Decoder {binary}} = case nullity of
Null -> Hasql.column $ Hasql.nullable binary
NotNull -> Hasql.column $ Hasql.nonNullable binary
Loading

0 comments on commit 971d4d6

Please sign in to comment.