Skip to content

How can I order a Maybe column? #355

@DougBurke

Description

@DougBurke

With (my actual data is a little more complicated than this, and the column isn't an integer, but is a also an instance of DBOrd)

data NotInteresting f = NotInteresting { ni :: Column f (Maybe Int64) }
  deriving stock (Generic)
  deriving anyclass (Rel8able)

notInterestingSchema :: TableSchema (NotInteresting Name)
notInterestingSchema = TableSchema {
  name = "ni"
  , columns = NotInteresting { ni = "nini" }
  }

getNI = orderBy (ni >$< desc) $ do
  row <- each notInterestingSchema
  pure row

I get

    • No instance for ‘DBOrd (Maybe Int64)’
        arising from a use of ‘desc’
    • In the second argument of ‘(>$<)’, namely ‘desc’
      In the first argument of ‘orderBy’, namely ‘(ni >$< desc)’
      In the first argument of ‘($)’, namely ‘orderBy (ni >$< desc)’

(this should be with rel8 1.6.0.0).

Is there a way to add an instance for something like

instance DBOrd a => DBOrd (Maybe a)

although this probably interacts with #310 and the choice of how to handle nulls, or some other way to write a query that lets be order on a maybe column?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions