You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to DSH, I haven't used it before, I'm trying to figure it out for the first time, so forgive me if I'm missing something. Basically, I have a table in a database where the fields are NULLable, and I expect to be able to map those nullable fields to Maybes in Haskell. Here's a simple example:
{-# LANGUAGE OverloadedLists #-}
import Database.DSH
import Data.Text (Text)
-- create table names (id serial not null, name varchar(256) null, constraint pk_names primary key(id));
names :: Q [(Integer, Maybe Text)]
names = table "names" ["id", "name"] (defaultHints [Key ["id"]])
This fails with the error:
Main.hs:8:25:
No instance for (DSH-0.13.0.1:Database.DSH.Frontend.Internals.BasicType
(Maybe Text))
arising from a use of ‘table’
In the second argument of ‘($)’, namely
‘table "names" ["id", "name"] (defaultHints [Key ["id"]])’
In the expression:
take (toQ 20)
$ table "names" ["id", "name"] (defaultHints [Key ["id"]])
In an equation for ‘names’:
names
= take (toQ 20)
$ table "names" ["id", "name"] (defaultHints [Key ["id"]])
If I replace Maybe Text with Text, then it compiles. But it will probably fail at runtime if it encounters a NULL from the database, right?
Could there or should there be an instance BasicType a => BasicType (Maybe a) somewhere in the guts of DSH to support this? Or alternatively, how can I detect NULL values in the database with DSH?
The text was updated successfully, but these errors were encountered:
NULL is not supported in DSH at the moment. If the database result contains NULL values due to nullable columns in base tables, DSH will fail.
I agree that representing nullable columns as Maybe is the right thing to do. The support for Maybe (and algebraic data types in general) in DSH represents data types by mapping them to nested lists. It should be possible to represent Nothing as NULL instead for a BasicType. This is somewhere on my TODO list, although not at the top.
Hi,
I'm new to DSH, I haven't used it before, I'm trying to figure it out for the first time, so forgive me if I'm missing something. Basically, I have a table in a database where the fields are
NULL
able, and I expect to be able to map those nullable fields toMaybe
s in Haskell. Here's a simple example:This fails with the error:
If I replace
Maybe Text
withText
, then it compiles. But it will probably fail at runtime if it encounters aNULL
from the database, right?Could there or should there be an instance
BasicType a => BasicType (Maybe a)
somewhere in the guts ofDSH
to support this? Or alternatively, how can I detectNULL
values in the database withDSH
?The text was updated successfully, but these errors were encountered: