@@ -5,12 +5,12 @@ module Database.Generic.Entity.DbTypes where
55import Data.Aeson qualified as Aeson
66import Data.ByteString (ByteString )
77import Data.ByteString.Char8 qualified as BS
8- import Database.Generic.Entity.FromDb (FromDbValues (.. ))
98import Database.Generic.Prelude
109import Database.HDBC qualified as HDBC
1110
1211data DbT f
13- = DbBytes ! (F f Bytes )
12+ = DbBool ! (F f Bool )
13+ | DbBytes ! (F f Bytes )
1414 | DbInt64 ! (F f Int64 )
1515 | DbInteger ! (F f Integer )
1616 | DbString ! (F f String )
@@ -32,6 +32,9 @@ deriving instance Show (DbT Unit)
3232class HasDbType a where
3333 dbType :: DbType
3434
35+ instance HasDbType Bool where
36+ dbType = DbBool Unit
37+
3538instance HasDbType Int64 where
3639 dbType = DbInt64 Unit
3740
@@ -46,20 +49,12 @@ deriving instance Aeson.ToJSON (DbT Id)
4649deriving instance Eq (DbT Id )
4750deriving instance Show (DbT Id )
4851
49- instance From Int64 DbValue where from = DbInt64
52+ instance From Bool DbValue where from = DbBool
53+ instance From Int64 DbValue where from = DbInt64
5054instance From String DbValue where from = DbString
5155
52- instance FromDbValues DbValue Int64 where
53- fromDbValues [DbInt64 i] = i
54- fromDbValues [DbInteger i] = unsafeFrom i
55- fromDbValues x = error $ " Error constructing Int64 from " <> show x
56-
57- instance FromDbValues DbValue String where
58- fromDbValues [DbBytes b] = from b
59- fromDbValues [DbString s] = s
60- fromDbValues x = error $ " Error constructing Int64 from " <> show x
61-
6256instance From HDBC. SqlValue DbValue where
57+ from (HDBC. SqlBool b) = DbBool b
6358 from (HDBC. SqlString s) = DbString s
6459 from (HDBC. SqlByteString b) = DbBytes $ Bytes b
6560 from (HDBC. SqlInt64 i) = DbInt64 i
0 commit comments