haskelldb icon indicating copy to clipboard operation
haskelldb copied to clipboard

How to use `haskelldb` as a library?

Open nurdann opened this issue 1 year ago • 4 comments
trafficstars

After running cabal init I tried adding haskelldb to .cabal file, e.g.

    build-depends:    
        base,
        haskelldb

But cannot cabal build

$ cabal build | tail
Error: cabal: Failed to build haskelldb-2.2.4 (which is required by
exe:smart-query from smart-query-0.1.0.0). See the build log above for
details.

    It could refer to
       either ‘Prelude.<>’,
              imported from ‘Prelude’ at src/Database/HaskellDB/Sql/Print.hs:15:8-35
              (and originally defined in ‘GHC.Base’)
           or ‘Text.PrettyPrint.HughesPJ.<>’,
              imported from ‘Text.PrettyPrint.HughesPJ’ at src/Database/HaskellDB/Sql/Print.hs:28:1-32
    |
186 |       CastSqlExpr typ expr -> text "CAST" <> parens (ppSqlExpr expr <+> text "AS" <+> text typ)
    |                                           ^^
[27 of 27] Compiling Database.HaskellDB.Version ( src/Database/HaskellDB/Version.hs, dist/build/Database/HaskellDB/Version.o, dist/build/Database/HaskellDB/Version.dyn_o )

nurdann avatar Jul 21 '24 06:07 nurdann

I suspect haskelldb is effectively unmaintained. You might like to try a library I wrote instead: Opaleye.

tomjaguarpaw avatar Jul 21 '24 11:07 tomjaguarpaw

I’m not keeping it up to date with GHC myself but glad to accept a PR.

m4dc4p avatar Jul 21 '24 15:07 m4dc4p

From what I understand the latest changes have it fixed? Based on diff

$ git diff v2.2.4 -- src/Database/HaskellDB/BoundedList.hs
diff --git a/src/Database/HaskellDB/BoundedList.hs b/src/Database/HaskellDB/BoundedList.hs
index 63d05ee..846f68a 100644
--- a/src/Database/HaskellDB/BoundedList.hs
+++ b/src/Database/HaskellDB/BoundedList.hs
@@ -86,7 +86,6 @@ class Size n where
     size :: n -> Int
 
 class (Size a, Size b) => Less a b
-
 class (Size a, Size b) => LessEq a b
 instance (Size a) => LessEq a a
 instance (Size a, Size b, Less a b) => LessEq a b
@@ -101,1277 +100,1277 @@ instance Less N0 N1
 data N2 = N2
 instance Size N2 where size _ = 2
 instance Less N1 N2
-instance Less a N1 => Less a N2
+instance (Size a, Less a N1) => Less a N2
 
 data N3 = N3
 instance Size N3 where size _ = 3
 instance Less N2 N3

So all it needs is to add a tag and publish it?

nurdann avatar Jul 21 '24 23:07 nurdann

I suspect haskelldb is effectively unmaintained. You might like to try a library I wrote instead: Opaleye.

Btw can you generate queries for other databases (MySQL, Redshift) besides PostgreSQL?

nurdann avatar Jul 21 '24 23:07 nurdann