@@ -16,7 +16,7 @@ relationAsCSV (Relation attrs tupleSet) = if relValAttrs /= [] then --check for
1616 else if V.length attrs == 0 then --check that there is at least one attribute
1717 Left $ TupleAttributeCountMismatchError 0
1818 else
19− Right $ encodeByName bsAttrNames (asList tupleSet)
19+ Right $ encodeByName bsAttrNames $ map RecordRelationTuple (asList tupleSet)
2020 where
2121 relValAttrs = V.toList $ V.filter (isRelationAtomType . atomType) attrs
2222 bsAttrNames = V.map (TE.encodeUtf8 . attributeName) attrs
@@ -26,19 +26,24 @@ instance ToRecord RelationTuple where
2626 toRecord tuple = toRecord $ map toField (V.toList $ tupleAtoms tuple)
2727-}
2828
29−instance ToNamedRecord RelationTuple where
30− toNamedRecord tuple = namedRecord $ map (\(k,v) -> TE.encodeUtf8 k .= v) (tupleAssocs tuple)
29+newtype RecordRelationTuple = RecordRelationTuple {unTuple :: RelationTuple}
30+
31+instance ToNamedRecord RecordRelationTuple where
32+ toNamedRecord rTuple = namedRecord $ map (\(k,v) -> TE.encodeUtf8 k .= (RecordAtom v)) (tupleAssocs $ unTuple rTuple)
33+
34+instance DefaultOrdered RecordRelationTuple where
35+ headerOrder (RecordRelationTuple tuple) = V.map (TE.encodeUtf8 . attributeName) (tupleAttributes tuple)
3136
32−instance DefaultOrdered RelationTuple where
33− headerOrder tuple = V.map (TE.encodeUtf8 . attributeName) (tupleAttributes tuple)
37+newtype RecordAtom = RecordAtom {unAtom :: Atom}
3438
35−instance ToField Atom where
36− toField (BoolAtom atom) = toField (if atom then "t" else "f")
37− toField (StringAtom atom) = toField atom
38− toField (IntAtom atom) = toField atom
39− toField (DateTimeAtom atom) = toField (show atom)
40− toField (DateAtom atom) = toField (show atom)
41− toField (DoubleAtom atom) = toField atom
42− toField (RelationAtom _) = error "Relation atoms cannot be used in CSV."
43−
39+instance ToField RecordAtom where
40+ toField ratom = case unAtom ratom of
41+ BoolAtom atom -> toField (if atom then "t" else "f")
42+ StringAtom atom -> toField atom
43+ IntAtom atom -> toField atom
44+ DateTimeAtom atom -> toField (show atom)
45+ DateAtom atom -> toField (show atom)
46+ DoubleAtom atom -> toField atom
47+ RelationAtom _ -> error "Relation atoms cannot be used in CSV."
48+ ByteStringAtom bs -> toField bs
4449