An attemt of generalization of "read from DB" operation.
- type FieldName = String
- type NoMoreThanOne_shoulditbe = Bool
- class (Typeable readable, Show pk) => ReadableFromDB readable pk where
- readFromDB :: Connection -> pk -> IO [Either AddressedReadFromDBError readable]
- parseDBrow :: Connection -> pk -> Map FieldName SqlValue -> IO (Either AddressedReadFromDBError readable)
- readOneFromDB :: Connection -> pk -> NoMoreThanOne_shoulditbe -> IO (Either AddressedReadFromDBError readable)
- type AllowedMaximumOfRowsCount = Int
- data ReadFromDBError
- data AddressedReadFromDBError = AddressedReadFromDBError {}
- wrapParseResult_1row :: (Typeable readable, Show pk) => pk -> Either ReadFromDBError readable -> Either AddressedReadFromDBError readable
- wrapParseResult_Nrows :: (Typeable a, Show pk) => pk -> [Either ReadFromDBError a] -> [Either AddressedReadFromDBError a]
- rightType_formReadResOrErr :: (Typeable left, Typeable right) => Either left right -> TypeRep
- takeFieldValue :: Convertible SqlValue a => FieldName -> Map FieldName SqlValue -> a
- takeUFieldValue :: Convertible SqlValue a => FieldName -> Map FieldName SqlValue -> a
- uppercaseMapKeys :: Map String a -> Map String a
- liftInList :: a -> [a]
ReadableFromDB
type NoMoreThanOne_shoulditbe = BoolSource
Type aliase for use by readOneFromDB
.
class (Typeable readable, Show pk) => ReadableFromDB readable pk whereSource
It's recommended to use newtypes for subject type variable ("readable"),
when it is composite (like tuple, Either, Map or other). Reason for that
is described near the ShowAsPCSI
instaniation
for AddressedReadFromDBError
.
readFromDB :: Connection -> pk -> IO [Either AddressedReadFromDBError readable]Source
Read rows from DB and parse each at once
using parseDBrow
class method
parseDBrow :: Connection -> pk -> Map FieldName SqlValue -> IO (Either AddressedReadFromDBError readable)Source
readOneFromDB :: Connection -> pk -> NoMoreThanOne_shoulditbe -> IO (Either AddressedReadFromDBError readable)Source
Class method derived from readFromDB
and parseDBrow
.
No need to overload it, if not for special cases.
type AllowedMaximumOfRowsCount = IntSource
Type aliase for use by TooManyResultsFoundInDB_RFDBE
.
data ReadFromDBError Source
What kind of errors are possible in the result of "read from DB" operation
data AddressedReadFromDBError Source
A wrapper around ReadFromDBError
, added information about type of
read subject and by showing the primary key.
___________
If PCLT is to be used for representation of AddressedReadFromDBError
then user must declare an additional localizable template in his PCLT
catalog with ID of form:
"ARFDBE_SDLR." ++ (show $ arfdbeEntityType
err)
, where the show
will include full modules path
of type. The templete content if not important - leave it empty, but what
is important - is it's SDL requirement. This SDL requirement wil be in
effect for the representation of arfdbeEntityType
AddressedReadFromDBError
.
For more information on that, see description for ShowAsPCSI
instance for
AddressedReadFromDBError
- in module Database.ReadableFromDB__.
wrapParseResult_1row :: (Typeable readable, Show pk) => pk -> Either ReadFromDBError readable -> Either AddressedReadFromDBError readableSource
In case of error it wraps it ReadFromDBError
into AddressedReadFromDBError
.
wrapParseResult_Nrows :: (Typeable a, Show pk) => pk -> [Either ReadFromDBError a] -> [Either AddressedReadFromDBError a]Source
Wrapper around wrapParseResult_1row
.
Helpers
rightType_formReadResOrErr :: (Typeable left, Typeable right) => Either left right -> TypeRepSource
Return the TypeRep
of what can be under Right
in Either
takeFieldValue :: Convertible SqlValue a => FieldName -> Map FieldName SqlValue -> aSource
This is better than row ! field_name
, because if an error occurs
(field not found), then it returns in error message this field name.
takeUFieldValue :: Convertible SqlValue a => FieldName -> Map FieldName SqlValue -> aSource
Uppercase given field name, and apply it with takeFieldValue
.
uppercaseMapKeys :: Map String a -> Map String aSource
WARNING !!!
HDBC lowercases field names, when using fetchAllRowsMap
.
liftInList :: a -> [a]Source
liftInList a = a : []