refactor: make Junction non-recursive (#1818)
Also Cardinality now includes a Junction or ConstraintName
This commit is contained in:
+14
-8
@@ -29,7 +29,8 @@ import Network.HTTP.Types.Header (Header)
|
||||
import PostgREST.ContentType (ContentType (..))
|
||||
import qualified PostgREST.ContentType as ContentType
|
||||
|
||||
import PostgREST.DbStructure.Relation (Link (..), Relation (..))
|
||||
import PostgREST.DbStructure.Relation (Cardinality (..),
|
||||
Junction (..), Relation (..))
|
||||
import PostgREST.DbStructure.Table (Column (..), Table (..))
|
||||
|
||||
import Protolude hiding (toS)
|
||||
@@ -106,15 +107,20 @@ compressedRel Relation{..} =
|
||||
in
|
||||
JSON.object $ [
|
||||
"origin" .= fmtTbl relTable
|
||||
, "target" .= fmtTbl relFTable
|
||||
, "cardinality" .= (show relType :: Text)
|
||||
, "target" .= fmtTbl relForeignTable
|
||||
] ++
|
||||
case relLink of
|
||||
Junction{..} -> [
|
||||
"relationship" .= (fmtTbl junTable <> fmtEls [constName junLink1] <> fmtEls [constName junLink2])
|
||||
case relCardinality of
|
||||
M2M Junction{..} -> [
|
||||
"cardinality" .= ("m2m" :: Text)
|
||||
, "relationship" .= (fmtTbl junTable <> fmtEls [junConstraint1] <> fmtEls [junConstraint2])
|
||||
]
|
||||
Constraint{..} -> [
|
||||
"relationship" .= (constName <> fmtEls (colName <$> relColumns) <> fmtEls (colName <$> relFColumns))
|
||||
M2O cons -> [
|
||||
"cardinality" .= ("m2o" :: Text)
|
||||
, "relationship" .= (cons <> fmtEls (colName <$> relColumns) <> fmtEls (colName <$> relForeignColumns))
|
||||
]
|
||||
O2M cons -> [
|
||||
"cardinality" .= ("o2m" :: Text)
|
||||
, "relationship" .= (cons <> fmtEls (colName <$> relColumns) <> fmtEls (colName <$> relForeignColumns))
|
||||
]
|
||||
|
||||
data PgError = PgError Authenticated P.UsageError
|
||||
|
||||
Reference in New Issue
Block a user