Skip to content

Upgrade 0.5.1.0 → 0.9.1.3: Query (Statement) with generic parameter (formerly using ToParam) #353

Description

@gasi

Hi Eitan,

I’m currently doing a big migration from Squeal 0.5.1.0 → 0.9.1.3 and I love it overall, especially how EncodeParams + DecodeRows gets rid of so much boilerplate.

Problem

I was able to figure out 95% of the work, but I get stuck on turning this query that used to take an arbitrary (generic?) parameter (using ToParam), that can convert to a PostgreSQL type, to a Statement with EncodeParams + DecodeRow. I had to revert and hard-code it to PGtext + Text which broke some of my queries that need PGtimestampz + UTCTime:

Statement: selectContentBy

image

Usage: getBy

image

I tried the following without luck:

selectContentBy ::
  (ToParam Schemas pgty hsty, SOP.Generic hsty) =>
  ( TableExpression 'Ungrouped '[] '[] Schemas '[pgty] from ->
    TableExpression 'Ungrouped '[] '[] Schemas '[pgty] from
  ) ->
  Statement Schemas hsty Content
selectContentBy clauses = Query encode decode sql
  where
    encode :: EncodeParams Schemas pgty hsty
    encode = aParam
    decode = decodeContentWithImage
    sql = -- ...

as I get this error ❌:

zoomhub/src/ZoomHub/Storage/PostgreSQL/Internal.hs:180:33: error: [GHC-18872]
    • Couldn't match kind ‘NullType’ with ‘*’
      When matching types
        pgty0 :: [*]
        '[pgty] :: [NullType]
      Expected: EncodeParams
                  '["public"
                    ::: [ZoomHub.Storage.PostgreSQL.Schema.Schema0.ConfigTable0,
                         ZoomHub.Storage.PostgreSQL.Schema.Schema3.ContentTable3,
                         ZoomHub.Storage.PostgreSQL.Schema.Schema0.ImageTable0,
                         ZoomHub.Storage.PostgreSQL.Schema.Schema0.FlickrTable0]]
                  '[pgty]
                  hsty
        Actual: EncodeParams Schemas pgty0 hsty
    • In the first argument of ‘Query’, namely ‘encode’
      In the expression: Query encode decode sql
      In an equation for ‘selectContentBy’:
          selectContentBy clauses
            = Query encode decode sql
            where
                encode :: EncodeParams Schemas pgty hsty
                encode = aParam
                decode = decodeContentWithImage
                sql = -- ...

I was thinking it might be something obvious you could spot right away. If not, I’m happy to go back and do the work to create a minimally reproducing example.

I appreciate your help 😄

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions